acm--Convention number is 1--hdoj 1014--uniform generator--water

Source: Internet
Author: User
Tags greatest common divisor


Hdoj Title Address: Portal



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

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


Test instructions: The title is smelly and long, can not understand, is to see whether the two number of greatest common divisor is 1, if 1 on the output good, otherwise output bad


#include <stdio.h> #include <iostream> #include <string.h> #include <memory.h>using namespace Std;int gcd (int a,int b) {   int r=0;   while (b!=0) {       r= a%b;       a=b;       b=r;   }   return A;} int main () {    int n,m;    while (scanf ("%d%d", &n,&m)!=eof) {        if (gcd (n,m) ==1) {            printf ("%10d%10d    good choice\n\n", n,m);        } else{            printf ("%10d%10d bad    choice\n\n", n,m);        }    }




acm--Convention number is 1--hdoj 1014--uniform generator--water

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.