标签:des style http color io os java ar strong
第k大GCD = GCD/第K大因子
3 2 3 1 2 3 2 8 16 3
1 -1 2
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long int LL;
LL gcd(LL a,LL b)
{
if(b==0) return a;
return gcd(b,a%b);
}
LL factor[1000100],n;
int main()
{
int T_T;
scanf("%d",&T_T);
while(T_T--)
{
LL x,y,k;
cin>>x>>y>>k;
LL g=gcd(x,y);
LL d=sqrt(g);
n=0;
for(LL i=1;i<=d;i++)
{
if(g%i==0)
{
LL j=g/i;
factor[n++]=i;
if(j!=i) factor[n++]=j;
}
}
sort(factor,factor+n);
if(k>n) puts("-1");
else
{
cout<<g/factor[k-1]<<endl;
}
}
return 0;
}
标签:des style http color io os java ar strong
原文地址:http://blog.csdn.net/ck_boss/article/details/39461065