ACGO欢乐赛#42题解
2025-03-10 20:37:45
发布于:浙江
24阅读
0回复
0点赞
Solution
暴力枚举从 到 的所有数看是否有为 的因数的就输出,否则无解。
Code
#include <bits/stdc++.h>
#include <cstdio>
#define int long long
#define ull unsigned long long
#define mod 998244353
#define MOD 1000000007
using namespace std;
const int N = 2e6 + 5,maxn = 3e3 + 5;
const double goldnum = (sqrt (5) + 1) / 2;
inline int read ()
{
int x = 0;
bool f = 1;
char c = getchar ();
while (c < '0' || c > '9') f = (c == '-' ? !f : f),c = getchar ();
while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48),c = getchar ();
return (f ? x : -x);
}
inline void write (int x)
{
if (x < 0) putchar ('-'),x = -x;
if (x > 9) write (x / 10);
putchar (x % 10 + '0');
return ;
}
signed main ()
{
int T;
cin >> T;
while (T --)
{
int a,b;
cin >> a >> b;
int f = 0;
for (int i = min (a,b);i >= 1;i --)
{
if (a % i == 0 && b % i == 0) f ++;
if (f == 2)
{
cout << i << endl;
break;
}
}
if (f == 1) cout << -1 << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个