This topic is not difficult, the key is to read English: (determine whether two numbers are coprime, and pay attention to the format of the output)
describing computer simulations usually requires random numbers. One way to generate a pseudo-random number is through a function of a certain form: seed (x+1) = [Seed (x) +Step]%mod which'%'is a modulo operator. Such a function will be generated in 0 and mod-pseudo-random number (seed) between 1. One of the problems with this form of action is that they will always generate the same pattern over and over again. To minimize this effect, carefully select the step and MoD values to make the 0 and mod-1The uniform distribution of all values between (including both). For example, if the step= 3 and mod =5, the function generates a series of pseudo-random number 0 in the repeating period,3,1,4,2。 In this example, all numbers between 0 and MOD-1 are generated in each mod iteration of the function. Note that the same seed is generated each time the seed (x) is produced (x +1The nature of the function means that if the function will be generated in 0 and mod-1 of all numbers, then it will evenly generate pseudo-random numbers with each mod iteration. If the step= 15 and mod = -, the function generates series 0, the,Ten,5(or any other repeating series if the initial seed is not 0). This is a poor step and mod selection because no initial seed will be generated from 0 and mod-1 of all numbers. Your program will determine whether the selection of step and mod will generate a uniform distribution of pseudo-random numbers. Enter each line of input to include a pair of integers for step and mod sequentially (1<= Step,mod <=100000). Output for each line of input, your program should right-align the output step values in columns 1th to 10th, the MoD values aligned to the right of column 11th to 20th, and the left-aligned output "good Choice" or "bad Choice" from the 25th column. When the MoD number is generated, selecting step and mod will generate 0 and mod-The "good Choice" message should be output when all numbers are between 1. Otherwise, your program should output the message "Bad Choice". After each output test set, the program should output a blank line. Sample Input3 5 the -63923 99999Sample Output3 5Good Choice the -Bad Choice63923 99999Good Choice
problem
1#include <iostream>2#include <cstdio>3 4 using namespacestd;5 6 intgcdintAintb)7 {8 returnA%B?GCD (b,a%b): b;9 }Ten One intMain () A { - Chartab[2][ the] = {"Bad Choice","Good Choice"} ; - intA, B; the while(~SCANF ("%d%d", &a, &b)) - { -printf ("%10d%10d%s\n\n", A, B, tab[gcd (b) = =1]) ; - } + return 0 ; -}
Thin Code
(HDU) 1014--uniform Generator (Unified random number Generation)