結果

問題 No.2177 Recurring ab
ユーザー ShirotsumeShirotsume
提出日時 2023-01-06 21:55:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 928 bytes
コンパイル時間 635 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 90,252 KB
最終ジャッジ日時 2024-05-07 21:28:34
合計ジャッジ時間 6,036 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 213 ms
89,856 KB
testcase_01 AC 142 ms
87,924 KB
testcase_02 AC 218 ms
90,108 KB
testcase_03 AC 210 ms
90,052 KB
testcase_04 AC 213 ms
89,776 KB
testcase_05 AC 217 ms
89,636 KB
testcase_06 AC 219 ms
90,084 KB
testcase_07 AC 217 ms
89,628 KB
testcase_08 AC 223 ms
89,856 KB
testcase_09 AC 217 ms
89,784 KB
testcase_10 AC 219 ms
90,252 KB
testcase_11 AC 222 ms
89,884 KB
testcase_12 AC 218 ms
89,856 KB
testcase_13 AC 226 ms
90,240 KB
testcase_14 AC 221 ms
89,600 KB
testcase_15 AC 222 ms
89,812 KB
testcase_16 AC 216 ms
89,856 KB
testcase_17 AC 220 ms
89,864 KB
testcase_18 AC 220 ms
89,600 KB
testcase_19 AC 218 ms
89,936 KB
testcase_20 AC 218 ms
89,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque, Counter
sys.setrecursionlimit(5 * 10 ** 5)
from pypyjit import set_param
set_param('max_unroll_recursion=-1')
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353
from fractions import Fraction
n = ii()
def check(n, a, b, p):
    return Fraction(a,p) / (1 - Fraction(1,(p**2))) + Fraction(b,(p**2)) / (1 - Fraction(1,(p**2))) > Fraction(1,n)
ans = 0

for a in range(0, 10):
    for b in range(0, 10):
        if a == b:
            continue
        if not check(n, a, b, max(a, b) + 1):
            continue
        ok = max(a, b) + 1
        ng = 10 ** 9 + 1
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if check(n, a, b, mid):
                ok = mid
            else:
                ng = mid
        ans += ok - max(a, b)
print(ans)
0