Hangzhou Electric 1014--Uniform Generator

Source: Internet
Author: User
Tags greatest common divisor

Uniform Generator

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 21219 Accepted Submission (s): 8308


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 value right-justified in columns one through 20 and either "Good Choice" or "bad Choice" left-justified starting in column. The "good Choice" message should is printed when the selection of STEP and MOD would generate all the numbers between and I Ncluding 0 and MOD-1 when MOD numbers is generated. Otherwise, your program should print the message "Bad Choice". After each output test set, your program should print exactly one blank line.

Sample Input
3 5  the  - 63923 99999

Sample Output
    3       5     Good Choice      20     
63923 99999 Good Choice

Consider a large number; Pay attention to the format;

1#include <stdio.h>2 #defineMAX 100010;3 4 intgcdintAintb//greatest common divisor;5 {6     if(!B)returnA;7     Else8     returnGCD (b,a%b);9 }Ten  One intMain () A { -     intM,n; -      while(~SCANF ("%d%d",&m,&N)) the     { -         intlen=gcd (m,n); -         if(len==1) -printf"%10d%10d Good choice\n\n"); +         Else -printf"%10d%10d Bad chioce\n\n"); +      A     }     at}
View Code
1#include <stdio.h>2 intMain ()3 {4     intM,n;5      while(~SCANF ("%d%d",&m,&N))6     {7printf"%10d%10d", m,n);8         intTotal=0, I;9          for(i=0;; i++)Ten         { OneTotal= (total+m)%N; A             if(total==0) -              Break; -         } the         if(i==n-1) -printf"Good choice\n"); -         Else -printf"Bad choice\n"); +printf"\ n"); -           +     } A     return 0; at}

Hangzhou Electric 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.