-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.c
52 lines (42 loc) · 893 Bytes
/
solution.c
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
#include <stdio.h>
int main()
{
// First part
unsigned long long A = 873;
unsigned long long B = 583;
unsigned long long AF = 16807;
unsigned long long BF = 48271;
int judge = 0;
for(int i=0; i<40000000; i++)
{
A *= AF;
A %= 2147483647;
B *= BF;
B %= 2147483647;
if((A & 0xFFFF) == (B & 0xFFFF))
judge++;
}
printf("First part: %u\n", judge);
// Second part
A = 873;
B = 583;
judge = 0;
for(int i=0; i<5000000; i++)
{
while(1==1)
{
A *= AF;
A %= 2147483647;
if(A%4==0) break;
}
while(1==1)
{
B *= BF;
B %= 2147483647;
if(B%8==0) break;
}
if((A & 0xFFFF) == (B & 0xFFFF))
judge++;
}
printf("Second part: %u\n", judge);
}