View Code of Problem 102

#include<bits/stdc++.h>
using namespace std;

int gcd(int a,int b)
{
    int temp;
    while(b)
    {    
        /*利用辗除法,直到b为0为止*/
        temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}
  
int main(){
	int x,y;
	while(scanf("%d %d",&x,&y)!=EOF)
	{
		if(y%x!=0)
			printf("0\n");
		else if(x==y)
			printf("1\n");
		else{
			int a=y/x;
			int count=2;
			for(int i=2;i<sqrt(a);i++)
				if(a%i==0&&gcd(a/i,i)==1)
					count+=2;
			printf("%d\n",count);
		}	
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 102