結果

問題 No.757 チャンパーノウン定数 (2)
ユーザー yuppe19 😺yuppe19 😺
提出日時 2018-12-05 20:39:25
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 355 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 1,803 ms
コンパイル使用メモリ 77,272 KB
実行使用メモリ 81,532 KB
最終ジャッジ日時 2023-09-27 11:00:44
合計ジャッジ時間 12,490 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
79,472 KB
testcase_01 AC 70 ms
76,420 KB
testcase_02 AC 117 ms
77,364 KB
testcase_03 AC 73 ms
77,736 KB
testcase_04 AC 153 ms
79,264 KB
testcase_05 AC 153 ms
79,804 KB
testcase_06 AC 183 ms
80,500 KB
testcase_07 AC 75 ms
78,960 KB
testcase_08 AC 197 ms
81,256 KB
testcase_09 AC 192 ms
80,948 KB
testcase_10 AC 70 ms
76,156 KB
testcase_11 AC 114 ms
77,448 KB
testcase_12 AC 73 ms
77,240 KB
testcase_13 AC 154 ms
79,040 KB
testcase_14 AC 146 ms
80,108 KB
testcase_15 AC 180 ms
80,640 KB
testcase_16 AC 74 ms
79,012 KB
testcase_17 AC 201 ms
80,864 KB
testcase_18 AC 194 ms
81,260 KB
testcase_19 AC 70 ms
76,544 KB
testcase_20 AC 109 ms
77,736 KB
testcase_21 AC 71 ms
77,192 KB
testcase_22 AC 152 ms
78,980 KB
testcase_23 AC 150 ms
79,884 KB
testcase_24 AC 175 ms
80,736 KB
testcase_25 AC 71 ms
79,120 KB
testcase_26 AC 190 ms
81,384 KB
testcase_27 AC 200 ms
80,952 KB
testcase_28 AC 238 ms
79,728 KB
testcase_29 AC 289 ms
80,768 KB
testcase_30 AC 190 ms
81,136 KB
testcase_31 AC 73 ms
78,864 KB
testcase_32 AC 198 ms
81,160 KB
testcase_33 AC 116 ms
77,892 KB
testcase_34 AC 226 ms
81,284 KB
testcase_35 AC 71 ms
78,860 KB
testcase_36 AC 174 ms
80,684 KB
testcase_37 AC 244 ms
80,656 KB
testcase_38 AC 233 ms
79,792 KB
testcase_39 AC 250 ms
80,244 KB
testcase_40 AC 355 ms
81,140 KB
testcase_41 AC 348 ms
81,188 KB
testcase_42 AC 75 ms
77,648 KB
testcase_43 AC 91 ms
78,756 KB
testcase_44 AC 347 ms
81,532 KB
testcase_45 AC 238 ms
79,428 KB
testcase_46 AC 78 ms
77,724 KB
testcase_47 AC 290 ms
80,936 KB
testcase_48 AC 153 ms
77,728 KB
testcase_49 AC 238 ms
80,172 KB
testcase_50 AC 191 ms
80,912 KB
testcase_51 AC 178 ms
80,732 KB
testcase_52 AC 70 ms
77,392 KB
testcase_53 AC 68 ms
76,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python2
# -*- coding: utf-8 -*-
# †
def rep(B, i):
    return (B**i - 1) / (B-1)

def g(B, i):
    if i == 1:
        return 1
    if i == 2:
        return B
    return (i-2) * B**(i-1) + rep(B, i-1) * (B-2) + 2


def f(B, D):
    lo, hi = 0, 10**6
    while hi - lo > 1:
        md = (lo + hi) / 2
        if g(B, md) <= D:
            lo = md
        else:
            hi = md
    pos = g(B, lo)
    dif = D - pos
    z, r = divmod(dif, lo)
    w = z + B**(lo-1)
    return (w / B**(lo-1-r)) % B

B = int(raw_input())
D = int(raw_input(), base=B)
res = f(B, D)
print res
0