#include<iostream> #include<vector> #include<algorithm> #include<string> #include<climits> #include<cmath> #include<unordered_map> #include<set> using namespace std; long gcd(long a, long b) { //辗转相除法 if (a % b == 0) return b; return gcd(b, a % b); } int main() { long x, y; while (cin >> x >> y) { if (x == y) { cout << 1 << endl; continue; } int sum = 0; for (long i = x; i <= sqrt(x * y); i++) { if (y % i == 0) { long j = y / i * x; //找到另一个值 if (gcd(i, j) == x) //求最大公约数 sum++; } } cout << sum * 2 << endl; } } |
Double click to view unformatted code.