Created
October 24, 2024 11:50
-
-
Save HamidMolareza/39beaf2fc7a033f896735ec743593fda to your computer and use it in GitHub Desktop.
A temporary solution for problem 294.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://quera.org/problemset/294 | |
#This solution is failed in test case 8. | |
import math | |
# Read coefficients a, b, and c | |
a = float(input()) | |
b = float(input()) | |
c = float(input()) | |
# Check if it's not a quadratic equation | |
if a == 0: | |
if b == 0: | |
if c == 0: | |
print("IMPOSSIBLE") # Infinite solutions scenario, not an equation technically | |
else: | |
print("IMPOSSIBLE") # No valid equation or solution | |
else: | |
# Linear equation: bx + c = 0 => x = -c / b | |
x = -c / b | |
print(f"{x:.3f}") | |
else: | |
# Calculate the discriminant | |
discriminant = b**2 - 4*a*c | |
if discriminant > 0: | |
# Two real solutions | |
x1 = (-b - math.sqrt(discriminant)) / (2 * a) | |
x2 = (-b + math.sqrt(discriminant)) / (2 * a) | |
# Print in ascending order | |
print(f"{min(x1, x2):.3f}") | |
print(f"{max(x1, x2):.3f}") | |
elif discriminant == 0: | |
# One real solution | |
x = -b / (2 * a) | |
print(f"{x:.3f}") | |
else: | |
# No real solutions | |
print("IMPOSSIBLE") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment