結果

問題 No.2177 Recurring ab
ユーザー KudeKude
提出日時 2023-01-06 21:47:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 726 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 86,892 KB
実行使用メモリ 76,168 KB
最終ジャッジ日時 2023-08-20 14:53:38
合計ジャッジ時間 3,671 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,232 KB
testcase_01 AC 76 ms
71,260 KB
testcase_02 AC 86 ms
75,856 KB
testcase_03 AC 74 ms
71,216 KB
testcase_04 AC 74 ms
71,156 KB
testcase_05 AC 77 ms
71,388 KB
testcase_06 AC 77 ms
75,244 KB
testcase_07 AC 77 ms
75,352 KB
testcase_08 AC 83 ms
76,020 KB
testcase_09 AC 83 ms
76,032 KB
testcase_10 AC 85 ms
75,684 KB
testcase_11 AC 78 ms
75,160 KB
testcase_12 AC 82 ms
75,872 KB
testcase_13 AC 78 ms
75,076 KB
testcase_14 AC 83 ms
75,880 KB
testcase_15 AC 83 ms
75,736 KB
testcase_16 AC 76 ms
71,292 KB
testcase_17 AC 81 ms
75,744 KB
testcase_18 AC 84 ms
76,168 KB
testcase_19 AC 84 ms
76,040 KB
testcase_20 AC 82 ms
75,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# p^2 x = ab.ababab
# x = 0.ababab
# (p^2-1)x = ab
# x=ab/(p^2-1)
# ab/(p^2-1) > 1/n
# ab n + 1 > p^2
# (ap + b) n - p^2 >= 0
# -p^2 + an p + bn >= 0
from math import isqrt
n = int(input())
ans = 0
for a in range(10):
    for b in range(10):
        if a == b:
            continue
        an = a * n
        bn = b * n
        def check(p):
            return p * (an - p) + bn >= 0
        l = 0
        r = 1
        while check(r):
            l = r
            r *= 2
        while r - l > 1:
            c = (l + r) // 2
            if check(c):
                l = c
            else:
                r = c
        pmx = min(l, 10 ** 9)
        pmn = max(2, a + 1, b + 1)
        ans += max(0, pmx - pmn + 1)
print(ans)
0