題目如下:
題目描述 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
題目描述 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
#include<stdio.h>
int asd1(int x,int y,int y0)//判斷最小公倍數是不是等於y0
{
int i;
for(i=x;;i+=x)
if(i%y==0)
return i-y0;
}
int asd2(int x,int y,int x0)//判斷最大公約數是不是等於x0
{
int i,r;
r=y%x;
while(r)
{
y=x;
x=r;
r=y%x;
}
return x-x0;
}
int main()
{
int x0,y0,p,q,sum=0;
while(scanf("%d%d",&x0,&y0)!=EOF)
{
for(p=x0;p<=y0;p+=x0)
for(q=x0;q<=y0;q+=x0)
{ if(!(asd1(p,q,y0))&&!(asd2(p,q,x0)))
sum++;
}
printf("%d\n",sum);
}
}
留作參考吧,找到了好幾種解法,個人更傾向於這種解法。