n 个小伙伴(编号从 00到 n-1n−1)围坐一圈玩游戏。按照顺时针方向给 nn个位置编号,从00 到 n-1n−1。最初,第 00号小伙伴在第 00号位置,第 11号小伙伴在第 11 号位置,……,依此类推。游戏规则如下:每一轮第 00 号位置上的小伙伴顺时针走到第mm 号位置,第 11号位置小伙伴走到第 m+1m+1 号位置,……,依此类推,第n − mn−m号位置上的小伙伴走到第 00 号位置,第n-m+1n−m+1 号位置上的小伙伴走到第11 号位置,……,第n-1n−1 号位置上的小伙伴顺时针走到第m-1m−1 号位置。
你可以参考如下链接:
计蒜客-2013-转圈游戏_小吴同学的博客-CSDN博客 n 个小伙伴(编号从 00 到 n-1n−1)围坐一圈玩游戏。按照顺时针方向给 nn 个位置编号,从 00 到 n-1n−1。最初,第 00 号小伙伴在第 00 号位置,第 11 号小伙伴在第 11 号位置,……,依此类推。游戏规则如下:每一轮第 00 号位置上的小伙伴顺时针走到第 mm 号位置,第 11 号位置小伙伴走到第 m+1m+1 号位置,……,依此类推,第 n-mn−m 号位置上的小伙... https://blog.csdn.net/weixin_41296877/article/details/105142328
如果对你有帮助,可以给我个采纳吗,谢谢!! 点击我这个回答右上方的【采纳】按钮
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int n,m,k,x;
scanf("%d %d %d %d",&n,&m,&k,&x);
int last=m;
int row=10;
while(k){
if(k%2==1){
last=last*row%n;
}
k=k/2;
row=row*row%n;
}
last=(x+last)%n;
cout<<last<<endl;
return 0;
}
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int n,m,k,x;
scanf("%d %d %d %d",&n,&m,&k,&x);
int last=m;
int row=10;
while(k){
if(k%2==1){
last=last*row%n;
}
k=k/2;
row=row*row%n;
}
last=(x+last)%n;
cout<<last;
return 0;
}
快速幂?
#include<bits/stdc++.h>
using namespace std;
ll ksm(ll k,ll x,ll mod)
{
ll res = 1;
x= x%mod;
while(k)
{
if(k&1)
res=(res*x)%mod;
k>>=1;
x=(x*x)%mod;
}
return res % mod;
}
int main()
{
ll n,m,k,x;
cin>>n>>m>>k>>x;
ll tmp=(n*m)/__gcd(n,m);
cout<<(ksm(k,10,tmp)*m+x)%n<<endl;
return 0;
}