View Code of Problem 102

#include<stdio.h>
#include<math.h>
int GCD(int a, int b){
	if(b==0) return a;
	else return GCD(b, a % b); 
}

int main(){
	int x, y;
	while(scanf("%d %d", &x, &y) != EOF) {
		if(x == y){
			printf("1\n");	
		}
		else{
			long long product = x * y; //x与y的乘积就是p * q; 
			long long bound = sqrt(product);
			long long i, j;
			int cnt = 0;
			for(i=x; i<=bound; i++){ //y是最小公倍数 
				if(product % i == 0 && GCD(i, product/i) == x){
						cnt++;
					//	printf("%d %d\n", i, j);
					}
			}
			printf("%d\n", 2*cnt);
			
		}//else
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 102