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;
}
posted @ 2018-10-18 23:27  ChunhaoMo  阅读(94)  评论(0编辑  收藏  举报