洛谷 P1965 转圈游戏 —— 快速幂

题目:https://www.luogu.org/problemnew/show/P1965

居然真的就只是 ( x + m * 10k % n ) % n

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,m,k,x;
int pw(int a,int b)
{
  int ret=1;
  for(;b;b>>=1,a=((ll)a*a)%n)
    if(b&1)ret=((ll)ret*a)%n;
  return ret;
}
int main()
{
  scanf("%d%d%d%d",&n,&m,&k,&x);
  printf("%lld
",(x+(ll)m*pw(10,k)%n)%n);
  return 0;
}
原文地址:https://www.cnblogs.com/Zinn/p/9647801.html