• 洛谷 P1072 Hankson 的趣味题


    #include<bits/stdc++.h>
    using namespace std;
    int p[100010];
    int p1[1010];
    int p2[1010];
    bool flag[500010];
    const int N=500000;
    int tot=0;
    int cnt,cnt2;
    int res;
    int m=0;
    int a0,a1,b0,b1;
    void init()
    {
        for(int i=2;i<=N;i++)
        {
            if(!flag[i])
            {
                p[++tot]=i;
            }
            for(int j=1;p[j]*i<=N;j++)
            {
                flag[p[j]*i]=1;
                if(i%p[j]==0) break;
            }
        }
    }
    void work(int num)
    {
        int ka0=0,ka1=0,kb0=0,kb1=0;
        while(a0%num==0) ka0++,a0/=num;
        while(a1%num==0) ka1++,a1/=num;
        while(b0%num==0) kb0++,b0/=num;
        while(b1%num==0) kb1++,b1/=num;
        if(ka0==ka1&&kb0==kb1)
        {
            if(ka1<=kb1)
            {
                res*=(kb1-ka1+1);
                return;    
            }    
            else
            {
                res=0;
                return;
            }
        } 
        else if(ka0==ka1&&kb0<kb1)
        {
            if(kb1>=ka1)
            {
                return;
            }
            else
            {
                res=0;
                return;
            }
        }
        else if(kb0==kb1&&ka0>ka1)
        {
            if(ka1<=kb1)
            {
                return;
            }
            else
            {
                res=0;
                return;
            }
        }
        else if(ka0>ka1&&kb0<kb1)
        {
            if(ka1==kb1)
               return;
            else
            {
                res=0;
                return;
            }    
        }
    } 
    int main()
    {
        init();
        int n;
        scanf("%d",&n);
        while(n--)
        {
            scanf("%d%d%d%d",&a0,&a1,&b0,&b1);
            cnt=0,cnt2=0;
            res=1;
            int tmpa0=a0,tmpa1=a1,tmpb0=b0,tmpb1=b1;
            for(int i=1;p[i]*p[i]<=tmpa0;i++)
            {
                if(tmpa0%p[i]==0)
                {
                    p1[++cnt]=p[i];
                    while(tmpa0%p[i]==0)
                    {
                        tmpa0/=p[i];
                    }
                }
            }
            if(tmpa0>1)
                p1[++cnt]=tmpa0;
            for(int i=1;p[i]*p[i]<=tmpa1;i++)
            {
                if(tmpa1%p[i]==0)
                {
                    p1[++cnt]=p[i];
                    while(tmpa1%p[i]==0)
                    {
                        tmpa1/=p[i];
                    }
                }
            }
            if(tmpa1>1)
                p1[++cnt]=tmpa1;
            for(int i=1;p[i]*p[i]<=tmpb0;i++)
            {
                if(tmpb0%p[i]==0)
                {
                    p1[++cnt]=p[i];
                    while(tmpb0%p[i]==0)
                    {
                        tmpb0/=p[i];
                    }
                }
            }
            if(tmpb0>1)
               p1[++cnt]=tmpb0;
            for(int i=1;p[i]*p[i]<=tmpb1;i++)
            {
                if(tmpb1%p[i]==0)
                {
                    p1[++cnt]=p[i];
                    while(tmpb1%p[i]==0)
                    {
                        tmpb1/=p[i];
                    }
                }
            }
            if(tmpb1>1)
              p1[++cnt]=tmpb1;
            /*for(int i=1;i<=cnt;i++)
               printf("%d ",p1[i]);
            printf("
    ");*/
            sort(p1+1,p1+1+cnt);
            for(int i=1;i<=cnt;i++)
            {
                if(p1[i]!=p1[i-1])
                   p2[++cnt2]=p1[i];
            }
            /*for(int i=1;i<=cnt2;i++)
               printf("%d ",p2[i]);
            printf("
    ");*/
            for(int i=1;i<=cnt2;i++)
            {
                work(p2[i]);
            }
            printf("%d
    ",res);
        }
    }
  • 相关阅读:
    Codeforces Round #563 (Div. 2)B;Ehab Is an Odd Person
    Codeforces Round #563 (Div. 2)C. Ehab and a Special Coloring Problem
    Codeforces Round #567 (Div. 2) A.Chunga-Changa
    Codeforces Round #569 (Div. 2) B. Nick and Array
    Codeforces Round #570 (Div. 3) B. Equalize Prices
    2019年银联极客挑战赛第一题
    js点击保存图片
    vant地区三级联动
    input 输入金额正则判断
    git 实用命令
  • 原文地址:https://www.cnblogs.com/lishengkangshidatiancai/p/10357924.html
Copyright © 2020-2023  润新知