結果

問題 No.3133 法B逆元
ユーザー Taka
提出日時 2024-03-03 19:49:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,937 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 409 ms
コンパイル使用メモリ 82,412 KB
実行使用メモリ 75,780 KB
最終ジャッジ日時 2025-05-02 20:50:43
合計ジャッジ時間 11,566 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

# import
import time

# input
N, B = map(int, input().split())
start_time = time.time()

if N == 0 and B == 1:
    print(0)
    
elif N == 0:
    print('NaN')

elif N == 1 and B == 1:
    print(0)

elif N % B == 0:
    print('NaN')

else:
    N = N % B
    K = 0
    
    while True:
        current_time = time.time()
        elapsed_time = current_time - start_time
        if elapsed_time >= 1.9:
            print('NaN')
            break
        
        if N == 0:
            ans = 0
            print(ans)
            break
        elif (K * B + 1) % N == 0:
            ans = (K * B + 1) // N
            print(ans)
            break
        else:
            K += 1
0