【luogu1965】【noip2013】 转圈游戏 [快速幂]

P1965 转圈游戏

我只是突然发现我没有放快速幂模板

int quick(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b&1) res=res*a%n;
        a=a*a%n;
        b>>=1;
    }
    return res;
}
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define rg register
 4 int n,m,k,x;
 5 
 6 inline int rd()
 7 {
 8     int x=0,w=0;char ch=0;
 9     while(!isdigit(ch)) w|=ch=='-',ch=getchar();
10     while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
11     return w?-x:x;
12 }
13 
14 int quick(int a,int b)
15 {
16     int res=1;
17     while(b)
18     {
19         if(b&1) res=res*a%n;
20         a=a*a%n;
21         b>>=1;
22     }
23     return res;
24 }
25 
26 int main()
27 {
28     n=rd(),m=rd(),k=rd(),x=rd();
29     printf("%d",(x%n+m*quick(10,k)%n)%n);
30     return 0;
31  } 
原文地址:https://www.cnblogs.com/lxyyyy/p/10882436.html