@ACM-ICPC 2018 焦作賽區網路預賽 : G: Give Candies (大數模)
阿新 • • 發佈:2018-12-10
求 %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; }