-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path36.cpp
More file actions
36 lines (30 loc) · 666 Bytes
/
36.cpp
File metadata and controls
36 lines (30 loc) · 666 Bytes
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
#include <iostream>
bool is_palindrome(std::string s) {
int i = 0;
int j = s.size() - 1;
while (i < j) {
if (s[i++] != s[j--]) return false;
}
return true;
}
std::string itos(int i, int base) {
std::string ans = "";
while (i != 0) {
ans += (char) ('0' + (i % base));
i /= base;
}
return ans;
}
int main(int argc, char const *argv[]) {
constexpr int limit = 1000000;
std::uint64_t ans = 0;
for (int i = 1; i < limit; ++i) {
if (is_palindrome(itos(i, 10)) && is_palindrome(itos(i, 2))) {
// std::cout << itos(i, 10) << std::endl;
// std::cout << itos(i, 2) << std::endl;
ans += i;
}
}
std::cout << ans << std::endl;
return 0;
}