HDU 1014 Uniform Generator

Source: Internet
Author: User

Uniform GeneratorTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 21845 Accepted Submission (s): 8566


Problem descriptioncomputer simulations often require random numbers. One-to-generate pseudo-random numbers is via a function of the form

Seed (x+1) = [Seed (x) + STEP]% MOD

Where '% ' is the modulus operator.

Such a function would generate pseudo-random numbers (seed) between 0 and MOD-1. One problem with functions of this form was that they would always generate the same pattern over and over. In order to minimize this effect, selecting the STEP and MOD values carefully can result in a uniform distribution of all Values between (and including) 0 and MOD-1.

For example, if STEP = 3 and MOD = 5, the function would generate the series of pseudo-random numbers 0, 3, 1, 4, 2 in a re Peating cycle. In this example, all of the numbers between and including 0 and MOD-1 would be generated every MOD iterations of the Functi On. Note this by the nature of the function to generate the same seed (x+1) every time seed (x) occurs means that if a function Would generate all the numbers between 0 and MOD-1, it'll generate pseudo-random numbers uniformly with every MOD Iterati Ons.

If STEP = + MOD =, the function generates the series 0, 5 (or any other repeating series if the initial SE Ed is other than 0). This is a poor selection of STEP and MOD because no initial seed would generate all of the numbers from 0 and MOD-1.

Your program would determine if choices of STEP and MOD would generate a uniform distribution of pseudo-random numbers.

Inputeach line of input would contain a pair of integers for STEP and MOD on that order (1 <= STEP, MOD <= 100000).

Outputfor each line of input, your program should print the STEP value right-justified in columns 1 through, the MOD V Alue right-justified in columns one through and either "good Choice" or "bad Choice" left-justified starting in column 2 5. The "good Choice" message should is printed when the selection of STEP and MOD would generate all the numbers between an D including 0 and MOD-1 when MOD numbers is generated. Otherwise, your program should print the message "Bad Choice". After the output test set, your program should print exactly one blank line.

Sample Input
3 515 2063923 99999

Sample Output
         3         5    good Choice    Choice     63923     99999    Good Choice

Sourcesouth Central USA 1996
Recommendjgshining


This problem is huge water, but there is a pit.

The first deceptive place: English question, too many words, let a person look at do not want to do, and the meaning of the title is also a bit difficult to understand.

The second pit from the output of the example can be seen, the appearance of Super Trouble, a careless on the PE, but also the space ... +_+


Not much nonsense, in short, very pit ╮(╯▽╰)╭. Back to the chase ...

The title means, give two number, want you to judge whether these two number is coprime, if coprime is "good Choice" , otherwise "bad choice", but the output format is very pit dad, various spaces, PE a few times before ...

( 10 columns per digit, 4 spaces between numbers and characters ) ...


/*author:zxpxxmemory:1600 kbtime:0 mslanguage:c++result:accepted*/#include <cstdio>int gcd (int a, int b) {    R Eturn!b? A:GCD (b,a%b);} int main () {    char str[2][15] = {"Bad Choice", "Good Choice"};    int a, B;    while (~SCANF ("%d%d", &a, &b))        printf ("%10d%10d    %s\n\n", A, B, STR[GCD (b) ==1]);    return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 1014 Uniform Generator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.