hdu 6063 RXD and math (规律题)

xiaoxiao2021-02-27  108

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long LL; LL multi_mod(LL a,LL b,LL c) { a%=c;b%=c; LL ans=0; while(b) { if(b&1) { ans+=a;ans%=c; b--; } b>>=1; a<<=1;a%=c; } return ans; } LL pow_mod(LL x,LL n,LL mod) { x%=mod; LL ans=1; while(n) { if(n&1) { ans=multi_mod(ans,x,mod); n--; } n>>=1; x=multi_mod(x,x,mod); } return ans; } int main() { LL n,k; int cnt=0; while(~scanf("%lld%lld",&n,&k)) { printf("Case #%d: %lld\n",++cnt,pow_mod(n,k,(LL)(1e9+7))); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-16514.html

最新回复(0)