結果

問題 No.1198 お菓子配り-1
ユーザー rei60rei60
提出日時 2020-08-30 15:07:00
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 880 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 54,392 KB
最終ジャッジ日時 2024-04-28 01:38:07
合計ジャッジ時間 1,660 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 43 ms
54,272 KB
testcase_02 AC 42 ms
53,760 KB
testcase_03 AC 41 ms
54,016 KB
testcase_04 AC 43 ms
54,016 KB
testcase_05 AC 42 ms
54,016 KB
testcase_06 AC 43 ms
54,272 KB
testcase_07 AC 42 ms
54,144 KB
testcase_08 AC 42 ms
53,888 KB
testcase_09 AC 42 ms
53,888 KB
testcase_10 AC 43 ms
53,888 KB
testcase_11 AC 42 ms
54,144 KB
testcase_12 AC 42 ms
54,144 KB
testcase_13 AC 43 ms
54,144 KB
testcase_14 AC 42 ms
54,016 KB
testcase_15 AC 43 ms
53,888 KB
testcase_16 AC 42 ms
53,888 KB
testcase_17 AC 43 ms
54,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

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 N == 1 or N == 4:
    print(-1)
elif 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