View Code of Problem 102

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
int gcd(int a,int b) //求最大公约数 
{
	if(b==0) return a;
	else return gcd(b,a%b);
}
int main()
{
	int x,y,k,i,j,d,m;
	while(scanf("%d%d",&x,&y)!=EOF)
	{
		k=0;
		for(i=x;i<=y;i++)//P 
			for(j=i+1;j<=y;j++)//Q
			{
				d=gcd(j,i);//最大公约数 
				m=j/d*i;//最小公倍数 
				if(d==x&&m==y)
				k++;
			}
			printf("%d\n",2*k);
	}
	return 0;
 }

Double click to view unformatted code.


Back to problem 102