uva350 Pseudo-Random Numbers
View Code
#include<stdio.h> int main() { int Z, I, M, L, i = 1; while(scanf("%d%d%d%d",&Z,&I,&M,&L) && (Z||I||M||L)) { int f[10002] = {0}, k = -1; do { k++; L = ((Z%M)*(L%M)+I)%M; f[L]++; }while(f[L]==1); printf("Case %d: %d\n",i++,k); } return 0; }