forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10211.cpp
54 lines (52 loc) · 804 Bytes
/
10211.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 <bits/stdc++.h>
using namespace std;
int main()
{
int T, B, D;
scanf("%d", &T);
while (T-- > 0 && scanf("%d %d", &B, &D) == 2)
{
assert(2 <= B && B <= 500 && 2 <= D && D <= 5000);
int found = 0;
for (int step = 0; step < 3; step++)
{
int z;
char *fmt;
if (step == 0)
{
z = 0, fmt = "Rightmost %d\n";
}
else if (step == 1)
{
z = 1, fmt = "Add all %d\n";
}
else
{
z = D - 1, fmt = "Alternate %d change sign\n";
}
for (int r = 1, x = 1; r <= D + 10; r++)
{
if (step > 0 && r > 1000)
{
break;
}
x = (x * B) % D;
if (x == z)
{
found++;
printf(fmt, r);
break;
}
}
}
if (found == 0)
{
printf("condition not found.\n");
}
if (T > 0)
{
printf("\n");
}
}
return 0;
}