結果

問題 No.955 ax^2+bx+c=0
ユーザー mkawa2
提出日時 2019-12-19 11:34:29
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,054 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-07-07 01:04:06
合計ジャッジ時間 6,233 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 102 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

from decimal import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def red(a, b, c):
    if a * b * c == 0: return (a, b, c)
    x, y, z = abs(a), abs(b), abs(c)
    while y != 0: x, y = y, x % y
    while z != 0: x, z = z, x % z
    return (a // x, b // x, c // x)

def main():
    a, b, c = MI()
    if a == 0:
        if b == 0:
            if c == 0:
                print(-1)
            else:
                print(0)
        else:
            print(1)
            print(-c / b)
        exit()
    a, b, c = red(a, b, c)
    a, b, c = Decimal(a), Decimal(b), Decimal(c)
    D = b ** 2 - 4 * a * c
    if D > 0:
        print(2)
        print((-b - D.sqrt()) / (2 * a))
        print((-b + D.sqrt()) / (2 * a))
    elif D == 0:
        print(1)
        print(-b / a / 2)
    else:
        print(0)
main()
0