Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1014
Topic meaning: Give STEP and mod, and then according to this formula: Seed (x+1) = [Seed (x) + STEP]% MOD, ask whether in a cycle can produce 0 ~ mod-1 number. Output "Good Choice" if possible, otherwise the output "bad Choice".
Long ago left the problem, previously thought the topic meaning long, thought is very difficult topic ... Today, see the "Short Code of the United States" to see this problem, simply did. Paper Tiger One!
You can initialize seed to 0, and then initialize i = 1 with a formula, because the initialized seed = 0 already occupies one time. The final judgment number is equal to MOD, is the word represents 0 ~ MOD-1 The number has appeared, output "Good Choice"
Finally, the format problem, STEP and MOD each occupy 10 columns, respectively, 1~10 and 11 ~ 20. String beginning in 25 columns, remember to output two blank lines after the answer!
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5 using namespacestd;6 7 intMain ()8 {9 intstep, mod;Ten while(SCANF ("%d%d", &step, &mod)! =EOF) One { A intD =0; - inti =1; - for(; d = (d+step)%mod; i++) the ; -printf"%10d%10d%s\n\n", step, mod, i = = mod?"Good Choice":"Bad Choice"); - } - return 0; +}
"The beauty of the code," said can be used, linear with congruential to do seed (x+1) = [A*seed (x) + STEP]% MOD, this problem is A = 1. The final thing is to judge Coprime, but some do not understand very well, and feel the code written to the very rules, although shorter but less readable .....
HDU 1014.Uniform Generator Problem Solving report