結果

問題 No.1198 お菓子配り-1
ユーザー NoneNone
提出日時 2021-03-13 17:43:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 2,647 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 81,956 KB
実行使用メモリ 64,456 KB
最終ジャッジ日時 2024-04-23 08:25:41
合計ジャッジ時間 1,716 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,140 KB
testcase_01 AC 39 ms
53,028 KB
testcase_02 AC 38 ms
53,396 KB
testcase_03 AC 40 ms
53,408 KB
testcase_04 AC 38 ms
53,160 KB
testcase_05 AC 40 ms
54,180 KB
testcase_06 AC 38 ms
53,108 KB
testcase_07 AC 40 ms
53,140 KB
testcase_08 AC 40 ms
53,348 KB
testcase_09 AC 39 ms
53,076 KB
testcase_10 AC 39 ms
53,656 KB
testcase_11 AC 39 ms
53,672 KB
testcase_12 AC 39 ms
53,892 KB
testcase_13 AC 40 ms
54,488 KB
testcase_14 AC 49 ms
64,456 KB
testcase_15 AC 41 ms
53,968 KB
testcase_16 AC 39 ms
53,152 KB
testcase_17 AC 40 ms
54,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_prime_MR(n):
    if n in [2, 7, 61]:
        return True
    if n < 2 or n % 2 == 0:
        return False
    d = n - 1
    d = d // (d & -d)
    L = [2, 7, 61] if n < 1<<32 else [2, 3, 5, 7, 11, 13, 17] if n < 1<<48 else [2, 3, 5, 7, 11, 13, 17, 19, 23] if n < 1<<61 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1: return False
            t <<= 1
    return True

def prime_counter(n):
    i = 2
    ret = {}
    mrFlg = 0
    while i*i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += 1 + i%2
        if i == 101 and n >= 2**20:
            while n > 1:
                if is_prime_MR(n):
                    ret[n], n = 1, 1
                else:
                    mrFlg = 1
                    j = _find_factor_rho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    if mrFlg > 0: ret = {x: ret[x] for x in sorted(ret)}
    return ret

def divisors(n):
    """ O(x^1/4)  O(10**9)の整数10**4個の約数列挙が可能 """
    primes=prime_counter(n)
    P=set([1])
    for key, value in primes.items():
        Q=[]
        for p in P:
            for k in range(value+1):
                Q.append(p*pow(key,k))
        P|=set(Q)
    P = sorted(list(P)) # 速度が欲しい時は消す
    return P

def _find_factor_rho(n):
    m = 1 << n.bit_length() // 8 + 1
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r-k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x-ys), n)
        if g < n:
            if is_prime_MR(g): return g
            elif is_prime_MR(n//g): return n//g


################################################################################################
import sys
input = sys.stdin.readline
from math import gcd

N=int(input())

d=divisors(N)

flg=0
for x in d:
    y=N//x
    if (x+y)%2==0 and x>y:
        flg=1

print(1 if flg else -1)
0