結果

問題 No.757 チャンパーノウン定数 (2)
ユーザー nanaenanae
提出日時 2018-12-05 01:16:43
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,215 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 88,900 KB
最終ジャッジ日時 2023-09-22 23:59:46
合計ジャッジ時間 8,981 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,236 KB
testcase_01 AC 74 ms
71,328 KB
testcase_02 AC 75 ms
71,192 KB
testcase_03 AC 75 ms
71,332 KB
testcase_04 AC 81 ms
71,312 KB
testcase_05 AC 77 ms
71,008 KB
testcase_06 AC 77 ms
71,500 KB
testcase_07 AC 74 ms
71,332 KB
testcase_08 AC 78 ms
71,428 KB
testcase_09 AC 76 ms
71,416 KB
testcase_10 AC 75 ms
71,336 KB
testcase_11 AC 75 ms
71,336 KB
testcase_12 AC 74 ms
71,408 KB
testcase_13 AC 75 ms
71,360 KB
testcase_14 AC 76 ms
71,280 KB
testcase_15 AC 77 ms
71,136 KB
testcase_16 AC 75 ms
71,440 KB
testcase_17 AC 77 ms
71,284 KB
testcase_18 AC 77 ms
71,008 KB
testcase_19 AC 72 ms
71,492 KB
testcase_20 AC 75 ms
71,444 KB
testcase_21 AC 75 ms
71,372 KB
testcase_22 AC 76 ms
71,452 KB
testcase_23 AC 74 ms
71,276 KB
testcase_24 AC 74 ms
71,524 KB
testcase_25 AC 73 ms
71,440 KB
testcase_26 AC 77 ms
71,196 KB
testcase_27 AC 77 ms
71,524 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 124 ms
75,988 KB
testcase_31 AC 90 ms
76,604 KB
testcase_32 AC 77 ms
71,460 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 86 ms
76,548 KB
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 AC 341 ms
86,316 KB
testcase_43 AC 734 ms
88,900 KB
testcase_44 RE -
testcase_45 RE -
testcase_46 AC 536 ms
87,680 KB
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 AC 78 ms
71,340 KB
testcase_51 AC 77 ms
71,136 KB
testcase_52 AC 73 ms
71,448 KB
testcase_53 AC 72 ms
71,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys

def main():
    b = int(input())
    n = int(input(), b) - 1
    # n = convert_base(b, input()) - 1


    # print(n)

    ok = 0
    ng = 10**5 + 1

    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2

        if get_length_d(b, mid) < n:
            ok = mid
        else:
            ng = mid

    # print('max_digit:', ok)
    # print('max_digit_length:', get_length_d(b, ok))

    dig = ok
    base = get_length_d(b, dig)
    bpdig = b**dig
    x = (n - base)//(dig+1) + bpdig - 1

    def get_remain_length(b, x):
        return (dig + 1) * (x - bpdig + 1)

    t = base + get_remain_length(b, x)

    # print(n)
    # print(t)

    s = reconvert(b, x+1)

    # print(s)

    print(s[n - t])


def get_length_d(b, d):
    return (d * b**(d+1) - (d+1) * b**d + 1) // (b - 1)

def convert_base(b, n):
    res = 0

    for ni in n:
        res = res*b + int(ni)

    return res

def reconvert(b, n):
    res = []

    while n > 0:
        res.append(str(n % b))
        n //= b

    res.reverse()

    return ''.join(res)

if __name__ == '__main__':
    assert convert_base(2, '1011') == 11
    assert reconvert(2, 7) == '111'
    assert reconvert(2, 6) == '110'
    main()
0