題目太考驗人了,沒耐心也看不懂啊!!
大神表示這題就是判斷是否互質,證明如下:
令 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;
}