Volver a la lista de problemas
Uniform Generator
408.c
#include <stdio.h> #include <stdlib.h> #include <string.h> unsigned int next(unsigned int num, unsigned int step, unsigned int mod) { return ((num+step)%mod); } int good_choice(unsigned int step, unsigned int mod) { int num=0; int i; for(i=0; i<mod-1; i++) { num = next(num, step, mod); if (num==0) { return 0; } } num = next(num, step, mod); if (num==0) { return 1; } else { return 0; } } int main(void) { char buf[1024]; unsigned int step, mod; while(fgets(buf, 1024, stdin)) { if (sscanf(buf, "%d %d", &step, &mod)!=2) { exit(1); } if (good_choice(step, mod)) { printf("%10d%10d Good Choice\n\n", step, mod); } else { printf("%10d%10d Bad Choice\n\n", step, mod); } } exit(0); }