結果

問題 No.2177 Recurring ab
ユーザー ShirotsumeShirotsume
提出日時 2023-01-06 21:55:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 318 ms / 2,000 ms
コード長 928 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 86,408 KB
最終ジャッジ日時 2023-08-20 15:02:25
合計ジャッジ時間 8,772 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 304 ms
86,208 KB
testcase_01 AC 232 ms
83,860 KB
testcase_02 AC 314 ms
85,976 KB
testcase_03 AC 303 ms
86,248 KB
testcase_04 AC 306 ms
86,316 KB
testcase_05 AC 303 ms
86,036 KB
testcase_06 AC 308 ms
86,068 KB
testcase_07 AC 310 ms
86,144 KB
testcase_08 AC 310 ms
86,184 KB
testcase_09 AC 318 ms
86,172 KB
testcase_10 AC 311 ms
86,212 KB
testcase_11 AC 301 ms
86,180 KB
testcase_12 AC 315 ms
86,272 KB
testcase_13 AC 313 ms
86,044 KB
testcase_14 AC 316 ms
86,052 KB
testcase_15 AC 306 ms
85,860 KB
testcase_16 AC 317 ms
86,312 KB
testcase_17 AC 311 ms
86,408 KB
testcase_18 AC 317 ms
86,056 KB
testcase_19 AC 313 ms
86,364 KB
testcase_20 AC 314 ms
86,180 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