题目太考验人了,没耐心也看不懂啊!!
大神表示这题就是判断是否互质,证明如下:
令 f(x) = seed(x) + step ;
那么seed 的序列 就是 a=f(x) 的模MOD 加法群。
因为题中要求这个加法群的大小 | <a> | = MOD。
所以 a == 1 (mod MOD ).
即( seed(x) + STEP ) == 1 (mod MOD).
又因为seed(x) 必定含有0,
所以 STEP == 1 (mod MOD ).
即 STEP 和 MOD 互质
辗转相除法,最后看留下来1还是0,结束。
输出一开始没注意,25格开始,是4个空格,PE两次,汗颜……
Uniform Generator
#include <iostream>
#include <iomanip>
using namespace std;
bool coprime(int a, int b)
{
if(a==0 || b==0 || a==b)
return false;
if(a==1 || b==1)
return true;
if(a>b)
return coprime(a%b,b);
if(a<b)
return coprime(b%a,a);
}
int main()
{
int step,mod;
while(cin >> step >> mod)
{
if(coprime(step,mod)==true)
{
cout << setw(10) << setiosflags(ios::right) << step;
cout << setw(10) << setiosflags(ios::right) << mod;
cout << " " << "Good Choice" << '\n' << endl;
}
else
{
cout << setw(10) << setiosflags(ios::right) << step;
cout << setw(10) << setiosflags(ios::right) << mod;
cout << " " << "Bad Choice" << '\n' << endl;
}
}
return 0;
}