-
Notifications
You must be signed in to change notification settings - Fork 0
/
350uva.cpp
54 lines (50 loc) · 1012 Bytes
/
350uva.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<iostream>
using namespace std;
int main()
{
unsigned long long int Z,I,L,M,temp,count,i=1;
while((cin>>Z>>I>>M>>L)&&(Z && L && I && M))
{
count=0;
temp=((Z*L+I)%M);
L=temp;
while(1)
{
L=((Z*L+I)%M);
if(temp==L)
break;
count++;
}
cout<<"Case "<<i++<<": "<<++count<<endl;
}
return 0;
}
/*#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define LLU long long unsigned int
#define LLD long long double
int main()
{
LLU Z,I,M,L,N,count,cases=0;
while(cin>>Z>>I>>M>>L)
{
if(!Z && !L && !I && !M)
break;
bool done[1000000]={false};
count=0;
while(1)
{
N=((Z*L+I)%M);
L=N;
if(done[L]) break;
done[L]=true;
count++;
}
cout<<"Case" <<++cases<<":"<<count<<endl;
}
return 0;
}*/