View Code of Problem 102

#include<bits/stdc++.h>
using namespace std;
int gcd(int,int);
int main(){
	int x,y;
	while(scanf("%d%d",&x,&y)!=EOF){  //PQ = XY 
		if(x == y || y % x !=0){
			if(x==y)cout<<1;
			else cout<<0;
			cout<<endl;
			continue;
		}
		int num = 0;
		int t = y / x;
		int sqr = (int)sqrt(t); 
		for(int i = 1;i<=sqr;i++){
			if(t % i ==0){
				if(gcd(i,t/i)==1)num+=2;
			}
		}
		cout<<num<<endl;
	}
	
	return 0;
} 
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
} 

Double click to view unformatted code.


Back to problem 102