View Code of Problem 102

#include<iostream>

using namespace std;

int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}

int main() {
	long long int P, Q;

	while (cin >> P >> Q) {
		int cnt = 0;
		long long int max = P * Q;
		if (Q % P != 0) {
			cout << 0 << endl;
		}
		else if (Q == P) {
			cout << 1 << endl;
		}
		else {
			for (long long int i = P; i * i <= max; ++i) {
				if (max % i == 0) {
					continue;
				}
				if (gcd(i, max / i) == P) {
					cnt += 2;
				}
			}
			cout << cnt << endl;
		}
	}
}

Double click to view unformatted code.


Back to problem 102