Start: Jun, 28, 2019 08:42:00
2019杭州师范大学第一届程序设计竞赛新生赛
End: Jun, 28, 2019 11:42:00
Time elapsed:
Time remaining:

Problem_ID: D
Result: Accepted
Time: 173ms
Memory: 1740kB
In contest: 1276

#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
ll n,q;
int gcd(ll x,ll y)
{
	if(y%x==0)
	return x;
	else
	{
		for(int i=sqrt(x)+1;i>=1;i--)
		{
			if(x%i==0&&y%i==0)
			return i;
		}
	}
}
int main()
{
	ll x,y,ans1=0;
     scanf("%lld%lld",&n,&q);
     while(q--)
     {
     	scanf("%lld %lld",&x,&y);
     	if(x<y)
     	ans1=gcd(x,y);
     	else
     	ans1=gcd(y,x);
     	ll ans2=2;
     	printf("%lld\n",min(ans2,ans1));
	 }
	 return 0;
}