有个坑题目告诉你了,就是开始给你的数不一定在循环里,可用第二个数作为判断种子
#include<stdio.h>
int generate(int z, int i, int m, int l)
{
return (z * l + i) % m;
}
int main()
{
int z, i, m, l, count = 1;
while (scanf("%d %d %d %d", &z, &i, &m, &l), z || i || m || l)
{
int period = 1, next;
int begin = generate(z, i, m, l);
l = begin;
while (1)
{
next = generate(z, i, m, l);
if (begin == next)
break;
l = next;
period++;
}
printf("Case %d: %d\n", count++, period);
}
return 0;
}