Content

求一元二次方程式 ax2+bx+c=0 的根

Input

每組輸入共一行,內含三個整數 a, b, c 以空白隔開。

Output

Two different roots x1=?? , x2=??

Two same roots x=??

No real root

PS: 答案均為整數,若有兩個根則大者在前

Sample Input #1
1 3 -10
Sample Output #1
Two different roots x1=2 , x2=-5
Sample Input #2
1 0 0
Sample Output #2
Two same roots x=0
Sample Input #3
1 1 1
Sample Output #3
No real root

 

 

Python:

"""
Two different roots x1=?? , x2=??
Two same roots x=??
No real root

"""

from sys import stdin
a,b,c=map(int,stdin.readline().split())
if (b**2)-(4*a*c)<0:
    print(f"No real root")
elif (b**2)-(4*a*c)==0:
    print(f"Two same roots x={-b//(2*a)}")
else:
    n=int(((b**2)-(4*a*c))**0.5)
    print(f"Two different roots x1={(-b+n)//(2*a)} , x2={(-b-n)//(2*a)}")

文章標籤
全站熱搜
創作者介紹
創作者 趴趴熊日常 的頭像
趴趴熊日常

資工趴趴熊的小天地

趴趴熊日常 發表在 痞客邦 留言(0) 人氣(120)