結果

問題 No.1198 お菓子配り-1
ユーザー rei60rei60
提出日時 2020-08-30 14:57:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 815 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 55,760 KB
最終ジャッジ日時 2024-04-27 07:51:13
合計ジャッジ時間 2,288 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 43 ms
54,264 KB
testcase_02 AC 42 ms
54,320 KB
testcase_03 AC 43 ms
54,940 KB
testcase_04 AC 43 ms
54,304 KB
testcase_05 AC 43 ms
55,436 KB
testcase_06 AC 42 ms
54,820 KB
testcase_07 AC 44 ms
55,520 KB
testcase_08 AC 44 ms
55,096 KB
testcase_09 AC 44 ms
54,828 KB
testcase_10 AC 43 ms
55,372 KB
testcase_11 AC 43 ms
54,412 KB
testcase_12 AC 43 ms
54,764 KB
testcase_13 AC 43 ms
54,832 KB
testcase_14 AC 42 ms
53,904 KB
testcase_15 AC 43 ms
54,676 KB
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import random
def is_prime(q,k=50):
    q = abs(q)
    #計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
 
    #n-1=2^s*dとし(但しaは整数、dは奇数)、dを求める
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    #判定をk回繰り返す
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        #[0,s-1]の範囲すべてをチェック
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True


N = int(input())

if is_prime(N):
    print(-1)
elif int(str(N)[-2:])%4 == 0:
    print(1)
elif int(str(N)[-2:])%2 == 0:
    print(-1)
else:
    print(1)
0