View Code of Problem 102

#include<iostream>
#include<string>
#include<cmath>
using namespace std;
long gcd(long a, long b) {
	if (b == 0)
		return a;
	return gcd(b, a%b);
}
int main() {
	long x, y;
	while (cin >> x >> y) {
		int sum = 0;
		for (long i = x; i <= sqrt(x*y); i += x) {
			double d = x*1.0 * y / i;
			if (gcd(i, d) == x && d - int(d) == 0) {
				sum += 2;
				if (i == sqrt(x*y)) sum--;
			}
		}
		cout << sum << endl;
	}
}

Double click to view unformatted code.


Back to problem 102