啊哈磊_编程从这里起步

标题: hankson的趣味题 [打印本页]

作者: 啊哈磊    时间: 2013-2-20 20:39
标题: hankson的趣味题
[code=Cpp width=740px]
#include<stdio.h>
#include<math.h>
int gcd (int a,int b)
{
    int t;
    t=a%b;
    while(t!=0)
    {
        a=b;
        b=t;
        t=a%b;  
    }
    return b;
}
int main()
{
    int a0,a1,b0,b1,i,j,t1;
    int sum=0;
    int n,t;
    scanf("%d",&n);
    for(j=1;j<=n;j++)
    {
        sum=0;
        scanf("%d%d%d%d",&a0,&a1,&b0,&b1);
        t=sqrt(b1);//这里很重要 不用枚举到b1,只要枚举到sqrt(b1),就好了,因为约数是成对出现的
        for(i=1;i<=t;i++)
        {
            if(b1%i==0)//首先要保证这个i是b1的约数
            {
                if(gcd(i,a0)==a1 && i*b0==b1*gcd(i,b0))
                {
                    sum++;
                }
               
                t1=b1/i;
                if(i!=t1 && gcd(t1,a0)== a1 && t1*b0==b1*gcd(t1,b0))
                    sum++;
                }
            }
         
        printf("%d\n",sum);
}
    return 0;
}
</math.h></stdio.h>[/code]

作者: 4399APPLE    时间: 2013-11-21 09:59
这些帖子怎么就只有我一个人回复???




欢迎光临 啊哈磊_编程从这里起步 (https://bbs.codeaha.com/) Powered by Discuz! X3.2