zoukankan      html  css  js  c++  java
  • POJ3696【欧拉函数+欧拉定理】

    题意:

    求最小T,满足L的倍数且都由8组成,求长度;

    思路:
    很强势的福利:

    图片拿出去食用更优

    //#include<bits/stdc++.h>
    #include<cstdio>
    #include<math.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
    
    
    LL eluer(LL n)
    {
            LL res=n,a=n;
            for(LL i=2;i*i<=a;i++)
                if(a%i==0)
                {
                        res=res/i*(i-1);
                        while(a%i==0)
                            a/=i;
                }
            if(a>1) res=res/a*(a-1);
            return res;
    }
    
    LL multi(LL x,LL y,LL mod)
    {
        LL ans=0;
        while(y)
        {
            if(y&1) ans=(ans+x)%mod;
            x=(x<<1)%mod;
            y>>=1;
        }
        return ans;
    }
    
    LL quickmul(LL x,LL g,LL mod)
    {
        LL ans=1;
        while(g)
        {
            if(g&1) ans=multi(ans,x,mod)%mod;
            x=multi(x,x,mod)%mod;
            g>>=1;
        }
        return ans;
    }
    
    int main()
    {
        int cas=1;
        LL L,A,B,res,ans;
        while(~scanf("%lld",&L)&&L)
        {
            A=L/__gcd(8LL,L);
            printf("Case %d: ",cas++);
            if(__gcd(10LL,9*A)!=1)
                puts("0");
            else
            {
                res=eluer(9*A);
                LL q=sqrt((double)res);
                bool flag=false;
                for(LL i=1;i<=q;i++)
                {
                    if(res%i==0&&quickmul(10,i,9*A)==1)
                    {
                        ans=i;
                        flag=true;
                        break;
                    }
                }
                if(!flag)
                {
                    for(LL i=q;i>=1;i--)
                    {
                        if(res%i==0&&quickmul(10,res/i,9*A)==1)
                        {
                            ans=res/i;
                            break;
                        }
                    }
                }
                printf("%lld
    ",ans);
            }
        }
        return 0;
    }
    
    


  • 相关阅读:
    Python3安装
    HTML基础
    Python Socket
    python常用模块
    JSON.stringify的三个参数
    判断数组中存在重复元素
    vant-ui表单验证
    如何计算出浏览器的帧数?requestAnimationFrame
    js判断两个区间是否存在交集
    怎么在组件内部判断出是否插入了slot
  • 原文地址:https://www.cnblogs.com/keyboarder-zsq/p/6777440.html
Copyright © 2011-2022 走看看