Submission #67524033
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/modint>
// using namespace atcoder;
// using mint = modint998244353;
using ll = long long;
#define fix(x) fixed << setprecision(x)
#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);
bool judge(ll x, int a){
vector<int> y;
while(x){
y.emplace_back(x%a);
x /= a;
}
auto z = y;
reverse(all(z));
return z==y;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll a,n;
cin >> a >> n;
ll ans = 0;
for(ll i=1;;++i){
string s = to_string(i);
auto t = s;
reverse(all(t));
auto p = stoll(s+t);
auto q = stoll(s.substr(0,(int)s.size()-1)+t);
if(q>n) break;
if(p<=n) ans += p * judge(p,a);
ans += q * judge(q,a);
}
cout << ans << '\n';
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Palindromic in Both Bases |
| User | houren |
| Language | C++ 23 (gcc 12.2) |
| Score | 350 |
| Code Size | 1166 Byte |
| Status | AC |
| Exec Time | 617 ms |
| Memory | 3692 KiB |
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 | 3424 KiB |
| 00-sample-02.txt | AC | 324 ms | 3432 KiB |
| 00-sample-03.txt | AC | 345 ms | 3564 KiB |
| 01-01.txt | AC | 1 ms | 3424 KiB |
| 01-02.txt | AC | 1 ms | 3488 KiB |
| 01-03.txt | AC | 617 ms | 3524 KiB |
| 01-04.txt | AC | 403 ms | 3412 KiB |
| 01-05.txt | AC | 324 ms | 3432 KiB |
| 01-06.txt | AC | 367 ms | 3500 KiB |
| 01-07.txt | AC | 334 ms | 3576 KiB |
| 01-08.txt | AC | 318 ms | 3484 KiB |
| 01-09.txt | AC | 448 ms | 3568 KiB |
| 01-10.txt | AC | 344 ms | 3692 KiB |
| 01-11.txt | AC | 1 ms | 3428 KiB |
| 01-12.txt | AC | 23 ms | 3404 KiB |
| 01-13.txt | AC | 1 ms | 3428 KiB |
| 01-14.txt | AC | 23 ms | 3568 KiB |
| 01-15.txt | AC | 1 ms | 3504 KiB |
| 01-16.txt | AC | 3 ms | 3496 KiB |
| 01-17.txt | AC | 1 ms | 3492 KiB |
| 01-18.txt | AC | 3 ms | 3560 KiB |
| 01-19.txt | AC | 427 ms | 3560 KiB |
| 01-20.txt | AC | 1 ms | 3636 KiB |
| 01-21.txt | AC | 2 ms | 3492 KiB |
| 01-22.txt | AC | 1 ms | 3396 KiB |
| 01-23.txt | AC | 1 ms | 3492 KiB |
| 01-24.txt | AC | 2 ms | 3572 KiB |
| 01-25.txt | AC | 2 ms | 3496 KiB |
| 01-26.txt | AC | 2 ms | 3576 KiB |
| 01-27.txt | AC | 19 ms | 3448 KiB |
| 01-28.txt | AC | 1 ms | 3504 KiB |
| 01-29.txt | AC | 1 ms | 3496 KiB |
| 01-30.txt | AC | 1 ms | 3420 KiB |