結果

問題 No.2177 Recurring ab
ユーザー FromBooskaFromBooska
提出日時 2023-03-08 22:08:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,103 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 75,476 KB
最終ジャッジ日時 2023-10-18 06:02:53
合計ジャッジ時間 3,521 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
75,144 KB
testcase_01 AC 64 ms
75,136 KB
testcase_02 AC 65 ms
75,364 KB
testcase_03 AC 65 ms
75,144 KB
testcase_04 AC 65 ms
75,148 KB
testcase_05 AC 65 ms
75,476 KB
testcase_06 AC 64 ms
75,372 KB
testcase_07 AC 65 ms
75,440 KB
testcase_08 AC 66 ms
75,368 KB
testcase_09 AC 65 ms
75,360 KB
testcase_10 AC 66 ms
75,360 KB
testcase_11 AC 63 ms
75,380 KB
testcase_12 AC 65 ms
75,420 KB
testcase_13 AC 65 ms
75,372 KB
testcase_14 AC 64 ms
75,388 KB
testcase_15 AC 64 ms
75,404 KB
testcase_16 AC 64 ms
75,352 KB
testcase_17 AC 65 ms
75,356 KB
testcase_18 AC 64 ms
75,356 KB
testcase_19 AC 66 ms
75,360 KB
testcase_20 AC 66 ms
75,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# a, b で全探索
# a, bが決まればそのときのp進数がどこまで行けるかも決まるはず
# p進数分数は、[a,b] (in p) / [p-1,p-1] (in p)と考えればいい
# https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q12186530002
# 二分探索で高速化

# https://science-log.com/python%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0tips%E9%9B%86/%E3%80%90python%E3%80%91%E8%A8%98%E6%95%B0%E6%B3%95%E3%81%AE%E5%A4%89%E6%8F%9B/
def N_to_Dec(digits, base):
    num = 0
    for digit in digits:
        num = num * base + digit
    return num

N = int(input())
ans = 0
for a in range(0, 10):
    for b in range(0, 10):
        if a == b:
            continue 
        
        OK = 1
        NG = 10**20
        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 numerator*N > denominator:
                OK = mid
            else:
                NG = mid  
        #print('a', a, 'b', b, 'OK', OK)
        ans += max(0, OK - max(a, b))
print(ans)
0