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
#include
#include
#include
#include
#include
#include
#include
#include
#include

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

 

转载于:https://www.cnblogs.com/Staceyacm/p/10781744.html

你可能感兴趣的:(Sum(欧拉降幂+快速幂))