奋战杭电ACM(DAY9)1014

题目太考验人了,没耐心也看不懂啊!!大哭ios

大神表示这题就是判断是否互质,证实以下:spa

令 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 互质
code

展转相除法,最后看留下来1仍是0,结束。orm

输出一开始没注意,25格开始,是4个空格,PE两次,汗颜……可怜ip

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;
}
相关文章
相关标签/搜索