結果

問題 No.550 夏休みの思い出(1)
ユーザー ebicochinealebicochineal
提出日時 2017-11-07 14:39:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,151 ms / 2,000 ms
コード長 2,425 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 77,440 KB
最終ジャッジ日時 2024-05-03 06:54:33
合計ジャッジ時間 6,631 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
77,008 KB
testcase_01 AC 99 ms
77,076 KB
testcase_02 AC 100 ms
76,800 KB
testcase_03 AC 95 ms
76,800 KB
testcase_04 AC 92 ms
77,248 KB
testcase_05 AC 91 ms
76,800 KB
testcase_06 AC 92 ms
77,376 KB
testcase_07 AC 91 ms
77,440 KB
testcase_08 AC 93 ms
77,184 KB
testcase_09 AC 69 ms
77,440 KB
testcase_10 AC 76 ms
77,268 KB
testcase_11 AC 81 ms
77,184 KB
testcase_12 AC 82 ms
77,056 KB
testcase_13 AC 40 ms
60,928 KB
testcase_14 AC 126 ms
69,376 KB
testcase_15 AC 63 ms
60,416 KB
testcase_16 AC 62 ms
67,712 KB
testcase_17 AC 57 ms
69,760 KB
testcase_18 AC 51 ms
64,640 KB
testcase_19 AC 92 ms
77,056 KB
testcase_20 AC 41 ms
60,160 KB
testcase_21 AC 44 ms
60,160 KB
testcase_22 AC 75 ms
76,960 KB
testcase_23 AC 71 ms
77,256 KB
testcase_24 AC 59 ms
71,936 KB
testcase_25 AC 79 ms
76,800 KB
testcase_26 AC 54 ms
70,016 KB
testcase_27 AC 55 ms
70,144 KB
testcase_28 AC 59 ms
71,936 KB
testcase_29 AC 97 ms
77,184 KB
testcase_30 AC 49 ms
65,280 KB
testcase_31 AC 69 ms
76,672 KB
testcase_32 AC 68 ms
77,056 KB
testcase_33 AC 78 ms
77,184 KB
testcase_34 AC 1,151 ms
77,056 KB
testcase_35 AC 52 ms
62,464 KB
testcase_36 AC 51 ms
62,208 KB
testcase_37 AC 84 ms
77,408 KB
testcase_38 AC 82 ms
77,056 KB
testcase_39 AC 88 ms
76,956 KB
testcase_40 AC 62 ms
69,504 KB
testcase_41 AC 80 ms
77,132 KB
testcase_42 AC 78 ms
76,892 KB
testcase_43 AC 90 ms
76,928 KB
testcase_44 AC 59 ms
69,632 KB
testcase_45 AC 53 ms
68,352 KB
testcase_46 AC 70 ms
76,800 KB
testcase_47 AC 67 ms
77,056 KB
testcase_48 AC 59 ms
67,072 KB
testcase_49 AC 40 ms
54,912 KB
testcase_50 AC 38 ms
54,656 KB
testcase_51 AC 71 ms
76,992 KB
testcase_52 AC 52 ms
68,864 KB
testcase_53 AC 53 ms
69,632 KB
testcase_54 AC 52 ms
68,864 KB
testcase_55 AC 54 ms
69,760 KB
testcase_56 AC 45 ms
60,672 KB
testcase_57 AC 47 ms
60,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#! /usr/bin/env python3
import itertools
import random

def rho(n):
    f = lambda x : (x * x + 1) % n
    x = y = 2
    d = 1
    while d == 1:
        x = f(x)
        y = f(f(y))
        d = gcd(abs(x - y), n)
    return d

def gcd(a, b):
    if a < b: a, b = b, a
    while b > 0 : b, a = a % b, b
    return a

def _primefactor(n):
    r = []
    a, b = 0, 2
    while b * b <= n:
        if n % b == 0:
            n //= b
            r += [b]
        else:
            b += 1 + a
            a = 1
    if n > 1 : r += [n]
    return r

def primefactor(n):
    r = []
    cnt = 0
    while cnt < 2 and n > 100000:
        cnt += 1
        d = rho(n)
        if d != n:
            n //= d
            r += _primefactor(d)
        else:
            break
    a, b = 0, 2
    while b * b <= n:
        if n % b == 0:
            n //= b
            r += [b]
        else:
            b += 1 + a
            a = 1
    if n > 1 : r += [n]
    
    return r
    
def f(A, B, C, a, b, c):
    for i, j, k in itertools.product([0, 1], repeat = 3):
        ai = a * [-1, 1][i]
        bj = b * [-1, 1][j]
        ck = c * [-1, 1][k]
        if sum([ai, bj, ck]) == -A and ai * bj * ck == -C and ai * bj + ai * ck + bj * ck == B:
            return 1, ai, bj, ck
    return 0, 0, 0, 0

def f2(A, B, C, a, b):
    for i, j in itertools.product([0, 1], repeat = 2):
        ai = a * [-1, 1][i]
        bj = b * [-1, 1][j]
        if sum([ai, bj]) == -A and ai * bj == B:
            return 1, ai, bj
    return 0, 0, 0

def main():
    A, B, C = map(int, input().split())
    p = primefactor(abs(C))
    t = [-1, 0, 1]
    if C != 0:
        for i in itertools.product([0, 1, 2], repeat = len(p)):
            a = b = c = 1
            for j, k in enumerate(i):
                if k == 0 : a *= p[j]
                if k == 1 : b *= p[j]
                if k == 2 : c *= p[j]
            d, a, b, c = f(A, B, C, a, b, c)
            if d:
                t = [a, b, c]
                break
        print(*sorted(t))
    else:
        p = primefactor(abs(B))
        for i in itertools.product([0, 1], repeat = len(p)):
            a = b = 1
            for j, k in enumerate(i):
                if k == 0 : a *= p[j]
                if k == 1 : b *= p[j]
            d, a, b = f2(A, B, C, a, b)
            if d:
                t = [a, b, 0]
                break
        print(*sorted(t))

if __name__ == '__main__':
    main()
0