結果

問題 No.1198 お菓子配り-1
ユーザー uni_pythonuni_python
提出日時 2020-08-28 21:40:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 3,037 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 87,300 KB
実行使用メモリ 76,032 KB
最終ジャッジ日時 2023-08-10 07:49:53
合計ジャッジ時間 2,480 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,292 KB
testcase_01 AC 73 ms
71,296 KB
testcase_02 AC 69 ms
71,356 KB
testcase_03 AC 69 ms
71,524 KB
testcase_04 AC 76 ms
71,344 KB
testcase_05 AC 70 ms
71,452 KB
testcase_06 AC 68 ms
71,304 KB
testcase_07 AC 68 ms
71,440 KB
testcase_08 AC 71 ms
71,592 KB
testcase_09 AC 69 ms
71,316 KB
testcase_10 AC 69 ms
71,444 KB
testcase_11 AC 71 ms
71,256 KB
testcase_12 AC 69 ms
71,224 KB
testcase_13 AC 69 ms
71,388 KB
testcase_14 AC 76 ms
76,032 KB
testcase_15 AC 68 ms
71,228 KB
testcase_16 AC 68 ms
71,376 KB
testcase_17 AC 69 ms
71,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    #約数列挙

    def gcd(a, b):
        while b: a, b = b, a % b
        return a
    def isPrimeMR(n):
        d = n - 1
        d = d // (d & -d)
        L = [2]
        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 0
                t <<= 1
        return 1
    def findFactorRho(n):
        m = 1 << n.bit_length() // 8
        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 isPrimeMR(g): return g
                elif isPrimeMR(n // g): return n // g
                return findFactorRho(g)
    #[(p1,n1),(p2,n2),...]の形で返す
    def primeFactor(n):
        i = 2
        ret = {}
        rhoFlg = 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 isPrimeMR(n):
                        ret[n], n = 1, 1
                    else:
                        rhoFlg = 1
                        j = findFactorRho(n)
                        k = 0
                        while n % j == 0:
                            n //= j
                            k += 1
                        ret[j] = k

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


    #約数列挙
    #10^6以下で約数の数が最大なのは720720の時(240個しかない!)
    def divisors(N):
        pf = primeFactor(N)
        ret = [1]
        for p in pf:
            ret_prev = ret
            ret = []
            for i in range(pf[p]+1):
                for r in ret_prev:
                    ret.append(r * (p ** i))
        return sorted(ret)
    
    flag=0
    d=divisors(N)
    for i in range(len(d)):
        a=d[i]
        b=d[-1-i]
        if b<=a:
            break
        else:
            if (b-a)%2==0:
                flag=1
                break
    
    
    if flag:
        print(1)
    else:
        print(-1)

        
    


main()
0