CF1804C

题目大意:你有个 nn 面体骰子(面上的数字是 00n1n-1 ),初始1的数字是 xx ,定义一种操作 f(x)f(x) 是让骰子走 n(n+1)2\frac{n*(n+1)}{2} 步(例如五面的初始在 33,走 f(2)f(2) 是走 3013 \to 0 \to 1

手推一下发现最多执行到 f(2n)f(2n) 因为考虑 $0\to 2n $ 这个过程,nf(2n)n|f(2n) ,因此 2n2n 步是循环的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<bits/stdc++.h>

using namespace std;

int n,x,T,p;

int main()
{
ios::sync_with_stdio(false);
cin>>T;
while(T--)
{
int flg=0;
cin>>n>>x>>p;
for(int i=1;i<=min(n*5,p);i++)
{
long long tmp=x+1ll*(i+1)*(i)/2;
// cout<<tmp<<endl;
if(tmp%n==0)
{
flg=1;
break;
}
}
if(flg) cout<<"YES\n";
else cout<<"NO\n";
}
return 0;
}