1. 程式人生 > >Uniform Generator HDU1014

Uniform Generator HDU1014

題意

給你公式seed(x+1) = [seed(x) + STEP] % MOD ,輸入step和mod,
問你是否可以從第一項0,算到mod,它們是否都不同
是 good choice 否則 bad choice

分析

列舉過去

code

#include<iostream>
#include<string.h>
#include<algorithm>
#include<string>
using namespace std;
#define ll long long
int a[100010];
int main(){
    //freopen("in.txt","r",stdin);
    int s,m;
    while(cin>>s>>m){
        int ans=0;
        int cnt=1;
        memset(a,0,sizeof(a));
        a[0]++;
        bool flag=0;
        while(1){
            if(cnt==m) {
                flag=1;
                break;
            }
          ans=(ans+s)%m;
          a[ans]++;
          if(a[ans]>1) break;
          cnt++;    
        }
        printf("%10d%10d",s,m);
        if(flag)
            cout<<"    Good Choice"<<endl<<endl;
        else
            cout<<"    Bad Choice"<<endl<<endl;

    }
    return 0;
}