結果

問題 No.757 チャンパーノウン定数 (2)
ユーザー yuppe19 😺yuppe19 😺
提出日時 2018-12-05 19:05:04
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 399 ms / 2,000 ms
コード長 642 bytes
コンパイル時間 2,441 ms
コンパイル使用メモリ 77,628 KB
実行使用メモリ 82,036 KB
最終ジャッジ日時 2023-09-27 01:10:22
合計ジャッジ時間 14,339 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
79,412 KB
testcase_01 AC 76 ms
76,536 KB
testcase_02 AC 124 ms
77,556 KB
testcase_03 AC 81 ms
77,984 KB
testcase_04 AC 166 ms
79,368 KB
testcase_05 AC 163 ms
80,500 KB
testcase_06 AC 196 ms
80,816 KB
testcase_07 AC 82 ms
79,172 KB
testcase_08 AC 215 ms
81,596 KB
testcase_09 AC 212 ms
81,436 KB
testcase_10 AC 76 ms
76,936 KB
testcase_11 AC 124 ms
77,868 KB
testcase_12 AC 78 ms
77,724 KB
testcase_13 AC 164 ms
79,576 KB
testcase_14 AC 164 ms
80,460 KB
testcase_15 AC 197 ms
80,820 KB
testcase_16 AC 82 ms
79,172 KB
testcase_17 AC 217 ms
81,636 KB
testcase_18 AC 211 ms
81,448 KB
testcase_19 AC 77 ms
76,700 KB
testcase_20 AC 124 ms
77,824 KB
testcase_21 AC 80 ms
77,624 KB
testcase_22 AC 165 ms
79,500 KB
testcase_23 AC 167 ms
80,488 KB
testcase_24 AC 197 ms
80,828 KB
testcase_25 AC 82 ms
79,168 KB
testcase_26 AC 216 ms
81,260 KB
testcase_27 AC 210 ms
81,372 KB
testcase_28 AC 265 ms
80,152 KB
testcase_29 AC 318 ms
80,720 KB
testcase_30 AC 213 ms
81,444 KB
testcase_31 AC 83 ms
79,384 KB
testcase_32 AC 217 ms
81,436 KB
testcase_33 AC 125 ms
77,640 KB
testcase_34 AC 244 ms
81,644 KB
testcase_35 AC 81 ms
79,200 KB
testcase_36 AC 196 ms
80,680 KB
testcase_37 AC 268 ms
81,132 KB
testcase_38 AC 253 ms
79,836 KB
testcase_39 AC 278 ms
80,468 KB
testcase_40 AC 394 ms
81,788 KB
testcase_41 AC 395 ms
82,036 KB
testcase_42 AC 80 ms
77,592 KB
testcase_43 AC 99 ms
79,000 KB
testcase_44 AC 399 ms
81,896 KB
testcase_45 AC 268 ms
79,676 KB
testcase_46 AC 83 ms
77,800 KB
testcase_47 AC 338 ms
81,132 KB
testcase_48 AC 176 ms
77,764 KB
testcase_49 AC 273 ms
80,556 KB
testcase_50 AC 217 ms
81,296 KB
testcase_51 AC 197 ms
80,684 KB
testcase_52 AC 80 ms
77,700 KB
testcase_53 AC 76 ms
76,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python2
# -*- coding: utf-8 -*-
# †
from math import log

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)
    m = int(log(w, B) + 1e-9) + 1
    return (w / B**(m-1-r)) % B

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