結果

問題 No.550 夏休みの思い出(1)
ユーザー ebicochinealebicochineal
提出日時 2017-11-07 13:35:35
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,316 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 87,188 KB
実行使用メモリ 83,796 KB
最終ジャッジ日時 2023-08-15 20:07:16
合計ジャッジ時間 10,147 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 258 ms
81,624 KB
testcase_01 AC 346 ms
78,528 KB
testcase_02 AC 343 ms
78,132 KB
testcase_03 AC 326 ms
78,528 KB
testcase_04 AC 129 ms
78,268 KB
testcase_05 AC 129 ms
78,388 KB
testcase_06 AC 162 ms
78,240 KB
testcase_07 AC 418 ms
78,112 KB
testcase_08 AC 345 ms
78,440 KB
testcase_09 AC 105 ms
77,988 KB
testcase_10 AC 107 ms
77,972 KB
testcase_11 AC 111 ms
77,952 KB
testcase_12 AC 111 ms
77,992 KB
testcase_13 AC 83 ms
76,452 KB
testcase_14 AC 170 ms
78,020 KB
testcase_15 AC 98 ms
76,476 KB
testcase_16 AC 96 ms
77,208 KB
testcase_17 AC 93 ms
78,028 KB
testcase_18 AC 90 ms
77,572 KB
testcase_19 AC 124 ms
78,132 KB
testcase_20 AC 81 ms
76,220 KB
testcase_21 AC 81 ms
76,464 KB
testcase_22 AC 106 ms
77,932 KB
testcase_23 AC 101 ms
78,064 KB
testcase_24 AC 96 ms
77,944 KB
testcase_25 AC 218 ms
78,324 KB
testcase_26 AC 97 ms
77,792 KB
testcase_27 AC 96 ms
77,576 KB
testcase_28 AC 97 ms
78,144 KB
testcase_29 AC 109 ms
78,312 KB
testcase_30 AC 89 ms
77,544 KB
testcase_31 AC 103 ms
77,912 KB
testcase_32 AC 105 ms
77,852 KB
testcase_33 AC 108 ms
77,932 KB
testcase_34 TLE -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

def rho(n):
    a = random.randint(0, n) + 1
    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)
    
    if n > 1:
        for i in range(10):
            d = rho(n)
            if d != n:
                n //= d
                r += primefactor(d)
                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