View Code of Problem 102

#include<iostream>
using namespace std;

int gcd(long a,long b){
	return (a%b==0)?b:gcd(b,a%b);
}

int main(void){
	long x,y;
	while(cin>>x>>y){
		int sum=0;
		if(y%x!=0){
			sum=0;
		}else if(y==x){
			sum=1;
		}else{
			for(long p=1;p*p<=(x*y);p++){
				if((x*y)%p==0){
					long q=(x*y)/p;
					if(gcd(p,q)==x){
						sum+=2;
					}
				}
			}
		}
		cout<<sum<<endl;
	}
}

Double click to view unformatted code.


Back to problem 102