@ACM-ICPC 2018 焦作赛区网络预赛 : G: Give Candies (欧拉降幂)

版权声明:岂曰无衣,与子同袍 https://blog.csdn.net/sizaif/article/details/82716668

题库: https://nanti.jisuanke.com/t/31716

求 ​​​​​​​2^(n-1) % mod2^{n-1}%mod ;  

刘汝佳紫书上.

代码:

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const ll mod=1e9+7;
ll quc(ll a,ll b)
{
    ll res=1;
    while (b)
    {
        if (b&1)
            res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}
int main()
{
    string str;
    int t;
    scanf("%d",&t);
    while (t--)
    {
        cin>>str;
        ll sum=0;
        for (int i=0;i<str.length();i++)
            sum=(1ll*sum*10%(mod-1)+1ll*(str[i]-'0')%(mod-1))%(mod-1);
        ll res=quc(1ll*2,sum)*quc(2,mod-2)%mod;
        printf("%lld\n",res);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sizaif/article/details/82716668
今日推荐