Submission #67534139
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a;
ll n;
bool ok(ll jin, ll x) {
deque<ll> dq;
while (x > 0) {
dq.push_back(x % jin);
x /= jin;
}
while (dq.size() > 1) {
if (dq.front() != dq.back()) return false;
dq.pop_front();
dq.pop_back();
}
return true;
}
ll res = 0;
ll palextend(ll x, int flag, int zero) {
deque<ll> dq;
while (x > 0) {
dq.push_front(x % 10);
x /= 10;
}
int sz = dq.size();
if (flag == 0) {
for (int i = 0; i < sz; i++) {
dq.push_back(dq[sz - 1 - i]);
}
}
else if (flag == 1) {
for (int i = 1; i < sz; i++) {
dq.push_back(dq[sz - 1 - i]);
}
}
ll res = 0;
for (ll d : dq) {
res *= 10;
res += d;
}
return res;
}
void solve() {
for (ll i = 0; i < sqrt(n) * 10; i++) {
ll x1 = palextend(i, true, 0);
ll x2 = palextend(i, false, 0);
if (x1 <= n && ok(a, x1)) {
res += x1;
//cout << x1 << "\n";
}
if (x2 <= n && ok(a, x2)) {
res += x2;
//cout << x2 << "\n";
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> a >> n;
solve();
cout << res << "\n";
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Palindromic in Both Bases |
| User | minpro |
| Language | C++ 20 (gcc 12.2) |
| Score | 350 |
| Code Size | 1222 Byte |
| Status | AC |
| Exec Time | 1659 ms |
| Memory | 3640 KiB |
Compile Error
Main.cpp: In function ‘ll palextend(ll, int, int)’:
Main.cpp:29:34: warning: unused parameter ‘zero’ [-Wunused-parameter]
29 | ll palextend(ll x, int flag, int zero) {
| ~~~~^~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 350 / 350 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt |
| All | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-01.txt | AC | 1 ms | 3512 KiB |
| 00-sample-02.txt | AC | 1521 ms | 3504 KiB |
| 00-sample-03.txt | AC | 1460 ms | 3440 KiB |
| 01-01.txt | AC | 1 ms | 3356 KiB |
| 01-02.txt | AC | 1 ms | 3440 KiB |
| 01-03.txt | AC | 1659 ms | 3356 KiB |
| 01-04.txt | AC | 1480 ms | 3472 KiB |
| 01-05.txt | AC | 1427 ms | 3528 KiB |
| 01-06.txt | AC | 1501 ms | 3512 KiB |
| 01-07.txt | AC | 1443 ms | 3428 KiB |
| 01-08.txt | AC | 1526 ms | 3548 KiB |
| 01-09.txt | AC | 1572 ms | 3568 KiB |
| 01-10.txt | AC | 1528 ms | 3504 KiB |
| 01-11.txt | AC | 1 ms | 3532 KiB |
| 01-12.txt | AC | 61 ms | 3484 KiB |
| 01-13.txt | AC | 1 ms | 3428 KiB |
| 01-14.txt | AC | 62 ms | 3356 KiB |
| 01-15.txt | AC | 1 ms | 3640 KiB |
| 01-16.txt | AC | 4 ms | 3536 KiB |
| 01-17.txt | AC | 1 ms | 3568 KiB |
| 01-18.txt | AC | 4 ms | 3508 KiB |
| 01-19.txt | AC | 1503 ms | 3464 KiB |
| 01-20.txt | AC | 1 ms | 3356 KiB |
| 01-21.txt | AC | 3 ms | 3504 KiB |
| 01-22.txt | AC | 1 ms | 3352 KiB |
| 01-23.txt | AC | 2 ms | 3468 KiB |
| 01-24.txt | AC | 2 ms | 3356 KiB |
| 01-25.txt | AC | 3 ms | 3448 KiB |
| 01-26.txt | AC | 3 ms | 3556 KiB |
| 01-27.txt | AC | 43 ms | 3480 KiB |
| 01-28.txt | AC | 1 ms | 3516 KiB |
| 01-29.txt | AC | 1 ms | 3444 KiB |
| 01-30.txt | AC | 1 ms | 3576 KiB |