提出 #67544830


ソースコード 拡げる

import sys
import os
from math import ceil, floor, sqrt, pi, factorial, gcd,lcm,sin,cos,tan,asin,acos,atan2,exp,log,log10, isqrt, comb
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import cmp_to_key, lru_cache, reduce, cache
from operator import add, iand, ior, itemgetter, mul, xor
from string import ascii_lowercase, ascii_uppercase, ascii_letters
from typing import *
from bisect import bisect, bisect_left, bisect_right
from heapq import heapify, heappop, heappush, heappushpop, nlargest, nsmallest
from sortedcontainers import SortedSet, SortedList, SortedDict
from itertools import product, accumulate,permutations,combinations, count, groupby
input = lambda: sys.stdin.readline().rstrip("\r\n")
I = input
II = lambda: int(I())
LI = lambda: list(input().split())
LII = lambda: list(map(int, input().split()))
sys.setrecursionlimit(10000000)
inf = float('inf')

A = II()
N = II()

ans = 0

# for i in range(min(N,9)+1):
#     str8 = []
#     n = i
#     while n>0:
#         str8+=str(n%8)
#         n//=8
#     if str8 == str8[::-1]:
#         ans += i
#         print(i)


str_n = str(N)
n = len(str_n)
topn = 10**((n+1)//2)
# print(topn)
for j in range(2):
    for i in range(1,int(topn)+1):
        str_i = str(i)
        len_i = len(str_i)
        bottom = str_i[:len_i-1+j][::-1]
        a = int(str_i+bottom)
        # print(i,j,str_i, bottom)
        if a > N:
            break
        str8 = []
        n = a
        while n>0:
            str8.append(n%A)
            n//=A
        str8n = (len(str8)+1)//2
        if str8[:str8n] == str8[-str8n:][::-1]:
            ans += a
            # print(a)
        
print(ans)

提出情報

提出日時
問題 C - Palindromic in Both Bases
ユーザ GeekMasahiro
言語 Python (PyPy 3.10-v7.3.12)
得点 350
コード長 1682 Byte
結果 AC
実行時間 864 ms
メモリ 88216 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 350 / 350
結果
AC × 3
AC × 33
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00-sample-01.txt AC 158 ms 86136 KiB
00-sample-02.txt AC 675 ms 88216 KiB
00-sample-03.txt AC 692 ms 87656 KiB
01-01.txt AC 154 ms 86444 KiB
01-02.txt AC 157 ms 86356 KiB
01-03.txt AC 864 ms 87996 KiB
01-04.txt AC 644 ms 87792 KiB
01-05.txt AC 644 ms 88036 KiB
01-06.txt AC 672 ms 87864 KiB
01-07.txt AC 656 ms 88028 KiB
01-08.txt AC 675 ms 87748 KiB
01-09.txt AC 849 ms 87932 KiB
01-10.txt AC 681 ms 87728 KiB
01-11.txt AC 164 ms 86424 KiB
01-12.txt AC 195 ms 88092 KiB
01-13.txt AC 165 ms 86168 KiB
01-14.txt AC 200 ms 88164 KiB
01-15.txt AC 185 ms 86144 KiB
01-16.txt AC 175 ms 87652 KiB
01-17.txt AC 159 ms 86344 KiB
01-18.txt AC 171 ms 87676 KiB
01-19.txt AC 776 ms 87844 KiB
01-20.txt AC 184 ms 87376 KiB
01-21.txt AC 166 ms 87504 KiB
01-22.txt AC 155 ms 86300 KiB
01-23.txt AC 163 ms 87420 KiB
01-24.txt AC 162 ms 87072 KiB
01-25.txt AC 166 ms 87268 KiB
01-26.txt AC 171 ms 87468 KiB
01-27.txt AC 186 ms 87944 KiB
01-28.txt AC 162 ms 86392 KiB
01-29.txt AC 160 ms 86128 KiB
01-30.txt AC 180 ms 86388 KiB