luogu1965 转圈游戏 (快速幂)

求(m*10^k+x)%n即可

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #define LL long long int
 5 using namespace std;
 6 
 7 LL rd(){
 8     LL x=0;char c=getchar();int neg=1;
 9     while(c<'0'||c>'9'){if(c=='-') neg=-1;c=getchar();}
10     while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
11     return x*neg;
12 }
13 
14 LL modp(LL x,int k,int n){
15     LL re=1;
16     while(k){
17         if(k&1) re=re*x%n;
18         k>>=1;x=x*x%n;
19     }return re;
20 }
21 
22 int main(){
23     int n=rd(),m=rd(),k=rd(),x=rd();
24     printf("%d\n",(modp(10,k,n)*m+x)%n);
25 }

 

posted @ 2018-08-02 20:12  Ressed  阅读(157)  评论(0编辑  收藏  举报