結果

問題 No.2177 Recurring ab
ユーザー FromBooskaFromBooska
提出日時 2023-12-22 18:32:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 868 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 66,140 KB
最終ジャッジ日時 2023-12-22 18:32:32
合計ジャッジ時間 2,784 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
66,128 KB
testcase_01 AC 45 ms
66,128 KB
testcase_02 AC 45 ms
66,136 KB
testcase_03 AC 47 ms
66,128 KB
testcase_04 AC 48 ms
66,128 KB
testcase_05 AC 45 ms
66,128 KB
testcase_06 AC 44 ms
66,128 KB
testcase_07 AC 49 ms
66,128 KB
testcase_08 AC 45 ms
66,140 KB
testcase_09 AC 45 ms
66,140 KB
testcase_10 AC 45 ms
66,140 KB
testcase_11 AC 44 ms
66,128 KB
testcase_12 AC 45 ms
66,132 KB
testcase_13 AC 44 ms
66,128 KB
testcase_14 AC 46 ms
66,132 KB
testcase_15 AC 45 ms
66,132 KB
testcase_16 AC 45 ms
66,128 KB
testcase_17 AC 45 ms
66,128 KB
testcase_18 AC 45 ms
66,132 KB
testcase_19 AC 45 ms
66,132 KB
testcase_20 AC 47 ms
66,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# p進数分数は[a,b] (in p) / [p-1,p-1] (in p)と考えればいい
# [a, b]で全探索. [a, b]ごとに合致するpの個数を二分探索で求める
# https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q12186530002

def N_to_Dec(digits, base): # digitsはリスト
    num = 0
    for digit in digits:
        num = num * base + digit
    return num

N = int(input())
ans = 0
for a in range(10):
    for b in range(10):
        if a != b:
            OK = 1
            NG = 10**9+1
            while (NG-OK)>1:
                mid = (NG+OK)//2
                numerator = N_to_Dec([a, b], mid)
                denominator = N_to_Dec([mid-1, mid-1], mid)
                if N*numerator>denominator:
                    OK = mid
                else:
                    NG = mid
            calc = max(0, OK-max(a, b))
            ans += calc
print(ans)
0