Posted on 2008-05-14 20:10
superman 阅读(456)
评论(0) 编辑 收藏 引用 所属分类:
ZOJ
1 /* Accepted 1278 C++ 00:00.00 840K */
2 #include <iostream>
3
4 using namespace std;
5
6 int main()
7 {
8 int z, i, m; bool x[10000];
9
10 int last, next, cnt, n = 1;
11 while(cin >> z >> i >> m >> last)
12 {
13 if(z == 0 && i == 0 && m == 0 && last == 0)
14 break;
15
16 memset(x, false, sizeof(x));
17
18 cnt = 0;
19 while(true)
20 {
21 next = (z * last + i) % m;
22
23 if(x[next])
24 break;
25
26 last = next;
27 x[next] = true;
28
29 cnt++;
30 }
31
32 cout << "Case " << n++ << ": " << cnt << endl;
33 }
34
35 return 0;
36 }
37