Title: Click to open link
Analysis: The problem requires a uniform generation of random numbers, there are two ways: 1 to the number of the generation to mark 2 to generate a random number of step and mod greatest common divisor not more than 1
Code One:
#include <stdio.h> #include <string.h>int a1[100010];int main () {int step,mod;while (~scanf ("%d%d",& STEP,&MOD) {int I;int k=0;memset (a1,0,sizeof (A1)), for (i=1;i<=mod-1;i++) { k= (k+step)%mod; if (A1[k]) break ; a1[k]++; } if (i!=mod) printf ("%10d%10d bad choice\n", step,mod); elseprintf ("%10d%10d good choice\n", step,mod); printf ("\ n");} return 0;}
Code two:
#include <stdio.h>int main () {int s,m;while (~scanf ("%d%d", &s,&m)) {int i,k=0;for (i=1;i<=m;i++) {if (s %i==0&&m%i==0&i>1) k=1;} if (k) printf ("%10d%10d bad choice\n", s,m), elseprintf ("%10d%10d good choice\n", s,m);p rintf ("\ n");} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hdoj 1014 Uniform Generator