【Give Candies】(费马小定理)

#include<bits/stdc++.h>
#define MAX 100005
#define mod 1000000007
using namespace std;
typedef long long ll;
char st[MAX];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        ll p=0;
        int i=0,j;
        scanf("%s",st);
        while(st[i]!='\0')
        {
            p*=10;
            p+=(st[i++]-'0');
            p%=(mod-1);
        }
        p=p-1;
        ll res=2,ans=1;
        while(p)
        {
            if(p&1) 
                ans=ans*res%mod;
            res=res*res%mod;
            p>>=1;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/kannyi/p/9655583.html
今日推荐