• Sum(欧拉降幂+快速幂)


    Input

    2

    Output

    2
    
            
     

    Hint

    1. For N = 2, S(1) = S(2) = 1. 2. The input file consists of multiple test cases.

    Sample Input

    2

    Sample Output

    2
    
            
      

    Hint

    1.  For N = 2, S(1) = S(2) = 1.
    
    2.  The input file consists of multiple test cases. 
    
            
     归律是2的n-1次方但是n太大就用到了欧拉降幂
    

    和之前的一道题很想,之前的是2的n次方https://blog.csdn.net/lbperfect123/article/details/86693581

    代码:

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<set>
    #include<vector>
    #include<map>
    #include<cmath>
    
    const int maxn=1e5+5;
    const int mod=1e9+7;
    typedef long long ll;
    using namespace std;
    
    char a[100005];
    ll x,z=mod;
    ll quickpow(ll x,ll y,ll z)
    {
        ll ans=1;
        while(y)
        {
            if(y&1)
                ans=ans*x%z;
            x=x*x%z;
            y>>=1;
        }
        return ans;
    }
    ll phi(ll n)
    {
        ll i,rea=n;
        for(i=2;i*i<=n;i++)
        {
            if(n%i==0)
            {
                rea=rea-rea/i;
                while(n%i==0)
                    n/=i;
             }
        }
        if(n>1)
            rea=rea-rea/n;
        return rea;
    }
    int main()
    {
        while(scanf("%s",a)!=EOF)
        {
            ll len=strlen(a);
            ll p=phi(z);
            ll ans=0;
            for(ll i=0;i<len;i++)
                ans=(ans*10+a[i]-'0')%p;
            ans+=p;
            printf("%lld
    ",quickpow(2,ans-1,z));
        }
        return 0;
    }
     
  • 相关阅读:
    gil
    异步
    字符串 最长回文字串
    字符串 最长公共前缀
    数组 合并区间
    python 排序
    2021.9.3 阿里笔试AK贴
    SIP协议详解
    fiddler抓包各字段的含义
    常见的HTTP状态码列表
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10781744.html
Copyright © 2020-2023  润新知