Obtain all the positive integer pairs so that their maximum approximate number is n, and the minimum public multiple is m.
The general idea is to find all the positive integer pairs so that their maximum approximate number is n, and the minimum public factor is m. (1 <= n, m <= 10 ^ 10)
The problem can be converted to: Set a and B to the integer pair, where n, a, B, and m can all be divided by n, the question is converted to the logarithm of m/n, where the maximum public approx. Is 1 and the minimum public multiple is m/n.
That is, the logarithm of m/n multiplied by 1 to m/n. It can be solved in O (sqrt (m/n.
#include #include
#include
#include
#include
#include
#define MAX 0x3f3f3f3f#define N 2000005typedef long long LL;using namespace std;int T;LL n, m;LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b);}int main(){ cin>>T;while(T--) { cin >> n >> m; if(m % n) { printf(0); continue; } LL x = m / n; int ans = 0; for(LL i = 1; i <= (LL)sqrt(x); i++) { if(x % i == 0) { LL j = x / i; if(gcd(i, j) == 1) ans++; } } printf(%d, ans); } return 0;}
??