-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path10176.cpp
43 lines (37 loc) · 940 Bytes
/
10176.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
/*
math > number theory > module arithmetic
difficulty: easy
date: 20/Mar/2020
problem: is a given binary number of 100 digits divisible by 131071?
by: @brpapa
*/
#include <iostream>
#include <vector>
#define ll long long
#define MOD 131071
using namespace std;
int main() {
vector<char> bin;
string str;
while (cin >> str) {
bin.clear(); for (char c : str) if (c != '#') bin.push_back(c);
while (str.back() != '#') {
cin >> str;
for (char c : str) if (c != '#') bin.push_back(c);
};
int N = bin.size();
// input em bin, de tamanho N
ll sum = 0;
for (int i = 0; i < N; i++) {
if (bin[i] == '0') continue;
// p = 2^(N-i-1)
ll p = 1;
int K = N-i-1; while (K--) p = (2*p)%MOD;
p %= MOD;
sum = (sum+p)%MOD;
}
sum %= MOD;
cout << (sum == 0? "YES":"NO") << endl;
}
return 0;
}