結果

問題 No.757 チャンパーノウン定数 (2)
ユーザー nanaenanae
提出日時 2018-12-05 00:38:39
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,219 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 86,996 KB
実行使用メモリ 79,444 KB
最終ジャッジ日時 2023-09-22 22:53:17
合計ジャッジ時間 9,908 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 WA -
testcase_09 AC 77 ms
71,256 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 WA -
testcase_18 AC 75 ms
71,196 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 75 ms
71,220 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 76 ms
71,396 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 AC 76 ms
71,204 KB
testcase_51 AC 74 ms
71,228 KB
testcase_52 RE -
testcase_53 AC 70 ms
71,256 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 = str(int(str(x+1), b))

    # 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