Encountered a very interesting topic, requiring two numbers of the number of K conventions (of course k=1 is greatest common divisor), such as
12 6 2
3
Range, A and b<=1e14,k<=1e9.
So violence is certainly not, the crux of the problem is: can be greatest common divisor divisible by the number of two number of conventions!! That's what you can do.
1#include <iostream>2#include <string>3#include <algorithm>4#include <vector>5#include <cstdio>6#include <cstring>7#include <cmath>8 using namespacestd;9typedefLong Longll;Ten ll A,b,k; One ll gcd (ll A,ll b) A { - returnB?GCD (b,a%b): A; - } the BOOLcmp (ll aa,ll BB) - { - returnAa>BB; - } +Vector<ll>Vec; - + intMain () A { atIos::sync_with_stdio (false); Cin.tie (0); - -Cin>>a>>b>>K; - -ll ans=gcd (A, b); - for(LL i=1; i*i<=ans;i++)//greatest common divisor divisible is also the number of Conventions! in { - if(ans%i==0) to { + Vec.push_back (i); -ll j=ans/i; the if(j!=i) Vec.push_back (j); * } $ }Panax Notoginseng - sort (Vec.begin (), Vec.end (), CMP); the if(K>vec.size ()) cout<<"No solution!"<<Endl; + Elsecout<<vec[k-1]<<Endl; A the return 0; +}
Finish.
Number of K conventions (simple mathematics, logic conversion)