zoukankan      html  css  js  c++  java
  • codevs 1172 Hankson 的趣味题

    woc....这题考细节处理。要注意代码的逻辑顺序还有不要作死地循环到sqrt+1。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    int t,a0,a1,b0,b1;
    int gcd(int a,int b) 
    {
        if(b==0) return a; 
        return gcd(b,a%b);
    } 
    void work()
    {
        scanf("%d%d%d%d",&a0,&a1,&b0,&b1);
        int r1=a0%a1,r2=b1%b0;
        if ((a0%a1!=0) || (b1%b0!=0)) printf("0
    ");
        else
        {
            int a,b,c,d,cnt=0;
            b=a0/a1;c=b1/b0;
            int up=sqrt(b1);
            for (int i=1;i<=up;i++)
            {
                if (b1%i==0)
                {
                    int x=i;
                    if ((gcd(x/a1,b)==1) && (gcd(c,b1/x)==1) && (x%a1==0))
                        cnt++;
                    x=b1/x;
                    if ((gcd(x/a1,b)==1) && (gcd(c,b1/x)==1) && (x%a1==0) && (x!=i))
                        cnt++;
                }
            }
            printf("%d
    ",cnt);
        }
    }
    int main()
    {
        scanf("%d",&t);
        for (int i=1;i<=t;i++)
            work();
        return 0;
    }
  • 相关阅读:
    ASP.Net 反射显示
    ASP.Net 反射简单工厂模式
    ASP.Net MVC生成验证码
    ASP.Net EF架构
    ASP.Net 邮箱发送
    ASP.Net 反射简单
    ASP.Net 显示
    新年快乐
    测试开发比
    Linkbot介绍
  • 原文地址:https://www.cnblogs.com/ziliuziliu/p/5744340.html
Copyright © 2011-2022 走看看