結果

問題 No.550 夏休みの思い出(1)
ユーザー ebicochinealebicochineal
提出日時 2017-11-07 12:57:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,526 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 80,348 KB
最終ジャッジ日時 2023-08-15 20:06:02
合計ジャッジ時間 11,869 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
77,568 KB
testcase_01 AC 162 ms
78,204 KB
testcase_02 WA -
testcase_03 AC 222 ms
78,456 KB
testcase_04 AC 461 ms
78,452 KB
testcase_05 WA -
testcase_06 AC 160 ms
78,260 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 133 ms
78,088 KB
testcase_10 AC 132 ms
78,072 KB
testcase_11 AC 135 ms
78,360 KB
testcase_12 AC 125 ms
78,000 KB
testcase_13 AC 91 ms
72,236 KB
testcase_14 AC 150 ms
77,152 KB
testcase_15 RE -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 135 ms
78,460 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 110 ms
77,744 KB
testcase_27 AC 111 ms
78,056 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 111 ms
77,956 KB
testcase_31 WA -
testcase_32 AC 125 ms
78,356 KB
testcase_33 AC 137 ms
78,152 KB
testcase_34 AC 1,619 ms
78,392 KB
testcase_35 AC 107 ms
77,148 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 144 ms
78,336 KB
testcase_40 AC 118 ms
78,168 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 116 ms
78,020 KB
testcase_46 AC 121 ms
78,268 KB
testcase_47 WA -
testcase_48 AC 115 ms
78,096 KB
testcase_49 RE -
testcase_50 AC 97 ms
72,096 KB
testcase_51 AC 138 ms
78,344 KB
testcase_52 AC 117 ms
78,032 KB
testcase_53 AC 127 ms
78,192 KB
testcase_54 AC 117 ms
77,552 KB
testcase_55 AC 121 ms
78,260 KB
testcase_56 AC 104 ms
76,372 KB
testcase_57 AC 103 ms
76,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def rf(x, a, n):
    return (x * x + a) % n

def rho(n):
    a = random.randint(1, n)
    x = y = 2
    d = 1
    while d == 1:
        x = rf(x, a, n)
        y = rf(rf(y, a, n), a, n)
        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, c = 5, 7, 2
    m = math.sqrt(n)
    
    for i in range(100):
        d = rho(n)
        if d != n :
            n //= d
            m = math.sqrt(n)
            r += [d]
            break
    
    while c < 4:
        if n % c < 1:
            n //= c
            m = math.sqrt(n)
            r += [c]
        else:
            c += 1
    
    while b <= m:
        if n % a < 1:
            n //= a
            m = math.sqrt(n)
            r += [a]
        elif n % b < 1:
            n //= b
            m = math.sqrt(n)
            r += [b]
        else:
            a += 6
            b += 6
    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