結果

問題 No.955 ax^2+bx+c=0
ユーザー りあん
提出日時 2019-12-18 01:31:02
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 732 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-09-18 22:02:03
合計ジャッジ時間 7,203 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 122
権限があれば一括ダウンロードができます

ソースコード

diff #

def mysqrt(x):
    ok = 1
    ng = 10**500
    while ok + 1 < ng:
        m = (ok + ng) // 2
        if m * m <= x:
            ok = m
        else:
            ng = m
    return ok

a, b, c = map(int, input().split())
if a == 0:
    if b == 0:
        print(-1 if c == 0 else 0)
    else:
        print(1)
        print(-c / b)
else:
    if a < 0:
        a, b, c = -a, -b, -c
    p = b * b - a * c * 4
    if p == 0:
        print(1)
        print(-0.5 * b / a)
    elif p > 0:
        f = 10 ** 100
        a *= f ** 2
        b *= f
        p = b * b - a * c * 4
        s = -0.5 * (mysqrt(p) + b) / a
        t = 0.5 * (mysqrt(p) - b) / a
        print(2)
        print(s * f)
        print(t * f)
    else:
        print(0)

0