3 2 3 1 2 3 2 8 16 3
1 -1 2
#include <iostream>
#include <string>
#include <cmath>
#include <cstring>
#include <set>
typedef __int64 ll;
using namespace std;
set<ll> s;
ll GCD(ll xx,ll yy)
{
ll r=1;
while(r!=0)
{
r=xx%yy;
xx=yy;
yy=r;
}
return xx;
}
int main()
{
int T;
ll x,y,k,gcd,count;
cin>>T;
while(T--)
{
count=0;
cin>>x>>y>>k;
gcd=GCD(x,y);
for(int i=1;i<=sqrt(gcd);i++)
{
if(gcd%i==0)
{
s.insert(i);
s.insert(gcd/i);
}
}
set<ll>::reverse_iterator rit;
for(rit=s.rbegin();rit!=s.rend();rit++)
{
//cout<<*rit<<" ";
count++;
if(count==k)
{
cout<<*rit<<endl;
break;
}
}
if(count<k)cout<<"-1"<<endl;
s.clear();
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。欢迎读者评论和指正
原文:http://blog.csdn.net/it142546355/article/details/47724397