View Code of Problem 102

#include<iostream>
using namespace std;

long yue(long a,long b){
	long temp=0;
	//if()
//	if(a==b)return 1;
	for(long i=2;i<=(a<b?a:b);i++){
		if(a%i==0&&b%i==0){
			temp=i;
		}
	}
	return temp;
}
long bei(long a,long b){
	long i;
//	if(a==b)return 1;
	for(i=(a>b?a:b);i<=a*b;i++){
		if(i%a==0&&i%b==0)break;
	}
	return i;
}
int main(){
	long x,y;
	while(cin>>x>>y){
		int c=0;
		//if(x==0||y==0)
		if(x==y){
			cout<<1<<endl;
		}
		else if(x==0&&x!=y)cout<<0<<endl;
		else{
			for(long i=(x<y?x:y);i<=(x>y?x:y);i++){
			for(long j=(x<y?x:y);j<=(x>y?x:y);j++){
				if(yue(i,j)==x&&bei(i,j)==y){
					c++;
				}
			}
		}
		cout<<c<<endl;
		}
		
	}

}

Double click to view unformatted code.


Back to problem 102