The topic is like this: Click to open the link
The main idea is to find all positive integer pairs so that they greatest common divisor to n and least common multiple to M. (1 <= N, M <= 10^10)
The problem can be converted to: set A, B is that integer pair, N, a, B., M, these 4 numbers can be divisible by n, can be divided by N, the title is converted to find out greatest common divisor 1, least common multiple for the logarithm of m/n.
That is to find the logarithm of the product in 1 to m/n and the m/n and coprime. can be resolved within O (sqrt (m/n)).
#include <algorithm> #include <cstdio> #include <cmath> #include <cstring> #include <cstdlib > #include <iostream> #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\n"); 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\n", ans); } return 0;}
Find all positive integer pairs so that they greatest common divisor to n and least common multiple to M