# 2020 CCPC Wannafly Winter Camp Day1H

## subject

7-8 1H. Maximum common divisor

There are three people, A,B,C, in which A and B share a mysterious number k, known as 1 < K < n.

Now A and C say, "The value of k equals x."

C doesn't trust A very much, so I want to check with B if K really equals x.B does not want to tell C the value of K directly, but B allows C to give a positive integer y (note that y can be greater than n), and B will answer gcd(k,y).

Now, given k,n, you need to help C determine such a y value so that C must be able to tell whether A is lying by B's answer.If you have more than one y like this, you need to output the smallest one.

Input format:
The first line of input is an integer T(1 < T < 50).

For each set of data, enter a row of two integers n,k(1 < k < n < 500).

Output Format
For each set of data, the output is an integer in a row representing the answer.If y does not exist, the output_1.

Input sample:
3
10 1
10 4
10 7

Output sample:
210
8
7

## thinking

At first my idea was, since I want to tell if this number is true or false, then I want to make sure that the Y I give makes gcd (k,y) unique i n 1-N and gcd(i, y) (1<=i<=n), so I can tell that if gcd (k,y) is unique, then x equals K. If it is not unique, X does not equal k, so just let gcd(i, y) be unique.(k,y) is unique. How can we be unique? Let y be a multiple of k, btw. First, explain why the 101 answer of Sample 1 is 210. First, we need a y so that gcd (1, 210) is unique in 1-10. Then multiply the prime numbers in 1-10 so that gcd (i, 210) (2<=i<=10) cannot be 1.So we just need to figure out how many times K are in 1-n, so we can turn the problem into 1, 2, 3...Make gcd (1, y) unique in n/k, that is, multiply the prime number of 1-n/k, and then multiply K. Multiply large numbers when out of range.

## Code

```#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
#define dbg(x) cerr << #x " = " << x <<endl;
typedef pair<int, int> P;
typedef long long ll;

const int MAXN = 1000;
int prime[MAXN];
int tot = 0;
bool is[MAXN];
void init()
{
memset(is, 1, sizeof(is));
is[0] = is[1] = 0;
for(int i = 2; i < MAXN; i++)
{
if(is[i])
{
prime[tot++] = i;
}
for(int j = 0; j < tot; j++)
{
if(prime[j] * i >= MAXN) break;
is[i * prime[j]] = 0;
if(i % prime[j] == 0) break;
}
}
}

struct BigInt
{
const static int mod = 10000;
const static int DLEN = 4;
int a[600], len;
BigInt()
{
memset(a, 0, sizeof(a));
len = 1;
}
BigInt(int v)
{
memset(a, 0, sizeof(a));
len = 0;
do
{
a[len++] = v % mod;
v/=mod;
}while(v);
}
BigInt operator *(const BigInt &b)const
{
BigInt res;
for(int i = 0; i < len; i++)
{
int up = 0;
for(int j = 0; j < b.len; j++)
{
int temp = a[i]*b.a[j] + res.a[i+j] + up;
res.a[i+j] = temp % mod;
up = temp / mod;
}
if(up != 0)
{
res.a[i+b.len] = up;
}
}
res.len = len + b.len;
while(res.a[res.len-1] == 0 && res.len > 1) res.len--;
return res;
}

void output()
{
printf("%d", a[len-1]);
for(int i = len-2; i >= 0; i--)
{
printf("%04d", a[i]);

}
printf("\n");
}
};

int main()
{

int t, n, k;
init();
scanf("%d", &t);
while(t--)
{
scanf("%d%d", &n, &k);
int l, r;
l = 1;
r = n/k;
BigInt ans(1);
for(int i = l; i <= r; i++)
{
if(is[i])
{
BigInt tmp(i);
ans = ans * tmp;
}
}
BigInt temp(k);
ans = ans * temp;
ans.output();
}
return 0;
}
```
Two original articles have been published. 1. Visits 16

Posted by townclown on Sun, 12 Jan 2020 18:44:07 -0800