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  } 

 

相关文章:

  • 2021-08-01
  • 2021-08-19
  • 2021-07-04
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2021-12-26
  • 2021-08-27
猜你喜欢
  • 2021-05-18
  • 2021-11-27
  • 2021-07-07
  • 2021-11-27
  • 2021-10-17
  • 2022-01-10
  • 2021-11-08
相关资源
相似解决方案