-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuva-10176.cpp
More file actions
67 lines (55 loc) · 1.31 KB
/
uva-10176.cpp
File metadata and controls
67 lines (55 loc) · 1.31 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
#define B 2
#define M 131071
using namespace std;
typedef unsigned long long ULL;
ULL bigMod(ULL P); /// returns B^P % M
int main()
{
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
char s[10005];
string number;
int Len, i, j;
ULL sum;
while (gets(s)) {
Len = strlen(s);
if (s[Len - 1] == '#') {
s[Len - 1] = '\0';
number += s;
Len = number.size();
sum = 0;
for (i = 0, j = Len - 1; i < Len; i++, j--) {
if (number[i] == '1') {
sum += bigMod(j);
}
}
if (sum % M == 0) {
printf("YES\n");
}
else {
printf("NO\n");
}
number.clear();
}
else {
number += s;
}
}
return 0;
}
ULL bigMod(ULL P)
{
if (P == 0) {
return 1 % M;
}
else if (P % 2 == 0) {
/// ULL result = bigMod(B, P / 2, M);
/// return ((result % M) * (result % M)) % M;
ULL result = bigMod(P / 2) % M;
return (result * result) % M;
}
else {
return ((B % M) * (bigMod(P - 1) % M)) % M;
}
}