(noip2013)转圈游戏

题目传送门sxazr
先找一下x号同学再次回到第x号需要多少次,把每次的位置记下来,10^k%次数,
输出就好了
代码

#include <iostream>
#include <cstdio>
#define LL long long
using namespace std;
LL n,m,k,x,ans[100001],g,s;
LL zr(int x)
{
	LL tmp=1,a=10;
	while(x){
		if(x%2) tmp=tmp*a%s;
		a=a*a%s;
		x/=2;
	}
	return tmp;
}
int main()
{
	cin>>n>>m>>k>>x;
	LL o=x;ans[0]=x;s++;
	for(int i=1;;i++){
		o=(o+m)%n;
		if(o==x) break;
		ans[i]=o;s++;
	}
	g=zr(k);
	cout<<ans[g];
}```

猜你喜欢

转载自blog.csdn.net/qq_42920137/article/details/88928235
今日推荐