标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2140 Accepted Submission(s): 596
#include<cstdio> #include<cstring> #include<algorithm> #include<math.h> #include<queue> #include<iostream> using namespace std; typedef long long LL; LL gcd(LL a,LL b){ return b==0?a:gcd(b,a%b); } LL p[10005]; LL cmp(LL a,LL b){ return a>b; } int main() { int tcase; scanf("%d",&tcase); while(tcase--){ LL a,b,k; scanf("%lld%lld%lld",&a,&b,&k); LL d = gcd(a,b); int id = 0; for(LL i=1;i*i<=d;i++){ ///筛选出所有因子 if(d%i==0){ if(i*i==d) p[id++]=i; else{ p[id++]=i; p[id++]=d/i; } } } if(id<k){ printf("-1\n"); } else{ sort(p,p+id,cmp); printf("%lld\n",p[k-1]); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5573429.html