题目描述 Description
输入二个正整数x0,y0(2<=x0<100000,2<=y0<=1000000),求出满足下列条件的P,Q的个数
条件: 1.P,Q是正整数
2.要求P,Q以x0为最大公约数,以y0为最小公倍数.
试求:满足条件的所有可能的两个正整数的个数.
输入描述 Input Description
二个正整数x0,y0
输出描述 Output Description
满足条件的所有可能的两个正整数的个数
样例输入 Sample Input
3 60
样例输出 Sample Output
4
WIKIOI难度等级:通过初赛
总耗时:346ms 内存占用:0kb 语言:C++ 代码:1042B
- #include <iostream>
- using namespace std;
- int gcd(int a,int b)
- {
- if(a<b)
- {
- return gcd(b,a);
- }
- if(b==0)
- {
- return a;
- }
- if(a&1)
- {
- if(b&1)
- {
- return gcd(b,a-b);
- }
- else
- return gcd(a,b>>1);
- }
- else
- {
- if(b&1)
- {
- return gcd(a>>1,b);
- }
- else
- {
- return gcd(a>>1,b>>1)<<1;
- }
- }
- }
- int main(int argc,char *argv[])
- {
- int x0,y0,i,j,sign=0,temp;
- cin>>x0>>y0;
- for(i=x0;i<=y0;i++)
- {
- for(j=x0;j<=y0;j++)
- {
- if(j%x0==0&&i%x0==0)
- {
- temp=gcd(i,j);
- if(temp==x0)
- {
- if(i*j/x0==y0)
- {
- sign++;
- }
- }
- }
- }
- }
- cout<<sign;
- return 0;
- }
转载于:https://blog.51cto.com/wenryxu/1188845