Skip to content
TheChatArchiveThe Chat Archive
DeepSeekDeepseek v3.2· deepseekHugging Face Frontier Reasoning Traces

You are given an equation: Ax2 + Bx + C = 0. Your task is to find the number of distinct…

  1. User

    You are given an equation:

    Ax2 + Bx + C = 0.

    Your task is to find the number of distinct roots of the equation and print all of them in ascending order. Input

    The first line contains three integer numbers A, B and C ( - 105 ≤ A, B, C ≤ 105). Any coefficient may be equal to 0.

    Output

    In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.

    Examples

    Input

    1 -5 6

    Output

    2 2.0000000000 3.0000000000

  2. DeepSeek Assistant

    We are given an equation: A x^2 + B x + C = 0. Need to find number of distinct roots and print them in ascending order. Coefficients A, B, C are integers within [-1e5, 1e5]. Could be zero.

    We need to consider all cases: linear if A=0, constant if A=0 and B=0, etc. Infinite roots occurs if all coefficients are zero: 0x^2+0x+0=0 => infinite solutions (any x). So print -1. If A=0 and B=0 but C != 0 => no solutions => 0. If A=0, B != 0 => linear equation: B x + C = 0 => root x = -C/B. One root. Note: B could be negative; need to compute as double. Since B and C are integers, we can compute as -C/(double)B. Print with at least 5 decimal digits; we can use standard formatting.

    If A != 0 => quadratic: discriminant D = B^2 - 4 A C. Evaluate carefully: D could be negative => no real roots => print 0. D = 0 => one double root (but we need distinct roots count, so 1 distinct root) => x = -B/(2A). D > 0 => two distinct roots: x1 = (-B - sqrt(D))/(2A), x2 = (-B + sqrt(D))/(2A). Need ascending order, so sort them. Because sqrt(D) > 0, so x1 <= x2 if A>0? Actually if A>0 then denominator positive, so -B - sqrt(D) < -B + sqrt(D) => x1 < x2. If A<0 then denominator negative, so ordering flips: For A<0, dividing by negative flips inequality, so need to compare. Safer: compute both as double then sort.

    Edge Cases: D could be zero but we treat as one root. However, note that if A=0 but B=0 and C=0 infinite roots; already covered.

    Precision: Print with at least 5 digits after decimal. Use fixed and setprecision to say 10? The example prints 10 digits? Actually example: "2.0000000000" shows 10 digits after decimal. So maybe they want 10 digits? But the problem says "at least 5 digits after the decimal point." So we can output with 10 digits to be safe. Use std::fixed and std::setprecision(10) or more.

    Also careful with -0.0: We need to avoid printing "-0.0000000000". This could happen if root is 0 but computed as -0.0 due to rounding. We can handle by checking if absolute value is less than some epsilon (like 1e-12) then treat as 0.0.

    Also integer overflow: A,B,C up to 1e5, B^2 up to 1e10, 4AC up to 41e51e5 = 4e10, D could be up to around 1e10+4e10=5e10 which fits in 64-bit integer. But we might use long long for D. int is 32-bit (max ~2e9) so need 64-bit. So use long long for discriminant calculation: D = BB - 4LLAC. Be careful with product: 4A*C could overflow 32-bit if A=1e5, C=1e5 => 4e10 > 2^31. So use long long.

    Now, for roots: compute sqrt(D) as double. Could be sqrt of large number but still within double range. Double can handle up to 1e308.

    Now, infinite roots: All coefficients zero => -1.

    No roots: either quadratic with D<0, or linear with B=0 and C!=0, or A=0,B=0,C!=0.

    One root: A=0,B!=0; or A!=0 and D=0.

    Two roots: A!=0 and D>0.

    Now, careful: if A=0 and B=0 but C=0 => infinite, already handled. So we need to check the order.

    Also consider the case A=0,B=0,C=0 => infinite => -1.

    Now, also consider that if A!=0 but D is very close to zero due to floating errors? No, D is integer computed exactly from ints; if it's 0 exactly, we treat as one root. If it's negative, no roots.

    Now, we must output with high precision. Use double.

    But there's a nuance: When printing double, we should ensure that the root is computed accurately. For linear equation x = -C/B, if B and C are integers, division yields exact rational if denominator divides numerator? Not necessarily, but double can represent with about 15-16 decimal digits; printing 10 digits is fine.

    Now, need to output the number of roots as integer first, then the roots each on separate line.

    Edge Cases: A=0, B!=0 but root might be -0.0 if C=0. Then x = 0.0. Should print "0.0000000000". Avoid "-0.0000000000". Use if (abs(root) < 1e-12) root = 0.0.

    Similarly for quadratic.

    Also consider ordering: For two roots, we need ascending. For one root, just that root.

    Also consider that if root is computed as double, we might have to output with exact fraction? Not necessary.

    Now, about formatting: Use std::fixed and std::setprecision(10). Or perhaps 15. But "at least 5 digits" so 10 is fine.

    Now test with examples: Input: 1 -5 6 => D=25-24=1>0 => roots: (5-1)/2=2, (5+1)/2=3? Actually formula: x = (5 ±1)/2? Wait: -B = 5, sqrt(D)=1 => x = (5 ±1)/(2) => 2 and 3. Yes.

    Now test other cases: A=0, B=0, C=5 => no roots => 0.

    A=0, B=0, C=0 => -1.

    A=0, B=3, C=6 => x=-2.0 => prints 1 then -2.0000000000? Actually root = -2.0, so negative sign fine.

    A=0, B=2, C=0 => x=0.0 => print 0.0000000000.

    A=1, B=2, C=1 => D=0 => root -1.0 => one root.

    A=1, B=0, C=0 => D=0 => root 0.0.

    Now consider A != 0, D > 0, but A negative: Example A=-1, B=0, C=4 => -x^2 + 4 =0 => x^2=4 => x=±2. So roots: 2 and -2? Actually -x^2+4=0 => multiply -1 => x^2-4=0 => x=±2. So we need ascending: -2, 2. Let's compute via formula: A=-1, B=0, C=4. D = 0 -4*(-1)4 = 16? Actually B^2 -4AC = 0 -4(-1)4 = 0 + 16 = 16. sqrt=4. Roots: (-B ± sqrt(D))/(2A) = (0 ± 4)/( -2 ) = ±4 / -2 = ∓2? So x1 = ( -4 )/(-2) = 2? Wait careful: Using formula: x = [ -B ± sqrt(D) ] / (2A). For A negative, denominator negative. If we take + sqrt: (-B + sqrt)/(2A) = (0+4)/(2(-1)) = 4/(-2) = -2. For - sqrt: (0-4)/(-2) = (-4)/(-2) = 2. So x = -2 and 2. So compute as: x1 = (-B - sqrt(D))/(2A) = (0-4)/(-2) = (-4)/(-2)=2. x2 = (-B + sqrt(D))/(2A) = (0+4)/(-2)= -2. So x1 = 2, x2 = -2. So x1 > x2. So we need to sort. So it's fine: compute both then sort ascending.

    Now for D=0: root = -B/(2*A). If A negative, still one root. No sorting needed.

    Now what about large values? Example A=100000, B=0, C=-1 => D = 0 -4100000(-1) = 400000 => sqrt=632.455... Roots: ± sqrt(D)/(2A) = ±632.455 /200000 ~ ±0.00316227. Should be accurate.

    Now, potential floating errors: When D is a perfect square, sqrt may still yield exact integer? Possibly, but double may represent integer exactly for up to 2^53. For D up to 5e10, which is < 2^53 (9e15), integer is represented exactly. sqrt of perfect square may be exact if the integer sqrt is exactly representable and sqrt returns integer exactly? sqrt of an integer that is a perfect square often yields integer exactly if the integer is exactly representable and sqrt is correctly rounded. Should be fine.

    Now, consider the case where A=0 and B!=0, but B and C large: x = -C/B. That could be non-terminating decimal. Print with 10 digits.

    Now, we must handle the infinite roots case: all coefficients zero => equation is 0=0, true for all x. So output -1.

    But there is another scenario: If A=0, B=0, C=0 -> infinite. Done.

    Now, check for degenerate quadratic: A != 0 but also B=0 and C=0 -> D=0, root 0.

    Now, we need to implement.

    But also: The problem says "in case of infinite root count print the only integer -1." So just print -1.

    Now, implement in C++ (I'll produce solution code). Use iostream, iomanip, cmath, algorithm.

    Pseudo:

    #include <bits/stdc++.h> using namespace std;

    int main() { long long A, B, C; // Actually int is fine but for discriminant we need long long. cin >> A >> B >> C;

    // Infinite?
    if (A == 0 && B == 0 && C == 0) {
        cout << -1 << endl;
        return 0;
    }
    
    if (A == 0) {
        // Linear: B x + C = 0
        if (B == 0) {
            // C != 0 (since infinite case already handled)
            cout << 0 << endl;
        } else {
            double root = -double(C) / B;
            // Adjust -0.0
            if (fabs(root) < 1e-12) root = 0.0;
            cout << 1 << endl;
            cout << fixed << setprecision(10) << root << endl;
        }
        return 0;
    }
    
    // Quadratic
    long long D = B*B - 4LL*A*C;
    if (D < 0) {
        cout << 0 << endl;
    } else if (D == 0) {
        double root = -double(B) / (2.0 * A);
        if (fabs(root) < 1e-12) root = 0.0;
        cout << 1 << endl;
        cout << fixed << setprecision(10) << root << endl;
    } else {
        double sqrtD = sqrt(double(D));
        double x1 = (-double(B) - sqrtD) / (2.0 * A);
        double x2 = (-double(B) + sqrtD) / (2.0 * A);
        if (x1 > x2) swap(x1, x2);
        // adjust near zero
        if (fabs(x1) < 1e-12) x1 = 0.0;
        if (fabs(x2) < 1e-12) x2 = 0.0;
        cout << 2 << endl;
        cout << fixed << setprecision(10) << x1 << endl;
        cout << fixed << setprecision(10) << x2 << endl;
    }
    
    return 0;
    

    }

    But we need to handle precision: Use std::fixed and setprecision(10) before output. Could also use 15.

    Now, double-check: For D=0, we print one root. But also if A=0 and B != 0 we print one root. That's correct.

    Now, check edge case: A != 0, B != 0, C whatever.

    But there's a nuance: When A != 0 and D > 0, we have two distinct roots, but they could be equal due to floating? No, distinct. Okay.

    Now, any other infinite root possibilities? Possibly if A=0, B=0, C=0 infinite, else not.

    But what about equation that reduces to identity like 0x^2+0x+0=0? That's it. No other.

    Thus solution is complete.

    But before finalizing, let's examine if there is any case where number of distinct roots is infinite but not all coefficients zero? For example, if A=0, B=0, C=0 we already have. Could there be scenario like A=0, B=0, C=0? That's it. So no.

    Now, consider if A=0, B=0, C!=0 => no roots. Good.

    Now, consider if A=0, B!=0, C!=0 => one root.

    Now, check for possible overflow in D: Use long long.

    Now, what about input as ints but we stored as long long? fine.

    Now, test with some tricky cases:

    Case: A=0, B=1, C=0 => root 0. Output: 1 then 0.0000000000.

    Case: A=0, B=2, C=4 => root -2.0 -> -2.0000000000.

    Case: A=0, B=-3, C=6 => root = -C/B = -6/(-3)=2.0 -> 2.0000000000.

    Case: A=2, B=0, C=0 => D=0 root 0.0.

    Case: A=2, B=0, C=8 => 2x^2+8=0 -> x^2=-4 -> D = -64 <0 => 0.

    Case: A=2, B=0, C=-8 => D = 64 >0 => roots: ± sqrt(64)/(4) = ±8/4=±2 -> -2,2.

    Check our compute: sqrtD=8, x1 = (-0 -8)/(4)= -8/4=-2; x2 = (-0+8)/(4)=8/4=2; sorted: -2,2. good.

    Now, potential issues: When A is large, double division might cause slight inaccuracies. For printing 10 digits, it's fine.

    Now, consider D a large perfect square: e.g., A=1, B=200000, C=0? Actually B^2 - 410 = B^2 = 4e10? B=100000 => 1e10, sqrt = 100000 exactly? sqrt(1e10) = 100000? Actually 100000^2 = 1e10, yes. So sqrt should be 100000 exactly. But double might represent 100000 exactly because integer within 53 bits. So fine.

    Now, but when D is not perfect square, we need to output with 10 digits after decimal. That's fine.

    Now, we also need to handle the case where the root is negative zero. The check with fabs < 1e-12 sets to 0.0.

    Now, check extreme: A=1, B=0, C=1 => D=-4 <0 => 0.

    Now, what about A=0, B=0, C=0 => infinite => -1.

    Now, what about A=0, B=0, C=0 is the only infinite case? Yes.

    Now, final code.

    But wait, there is a nuance: In quadratic, when D > 0, there are two distinct real roots. But if A is very small and D is also very small, the roots could be large. But okay.

    Also consider that the problem may ask to print the roots in ascending order, and if there is only one root, just that root.

    Also, note: The problem statement: "In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point." So in case of 1 root, print "1" and then the root.

    Now, ensure that we don't print extra spaces.

    Now, code.

    But I should double-check handling of floating point zero: If root is -0.0000000000, they may consider as wrong? Better to set to 0.0.

    Now, maybe they require exactly 10 digits after decimal? The example shows 10 digits. But problem says at least 5, so 10 is safe.

    Alternatively, we can set precision to 15 and it will print trailing zeros? Actually if we use fixed and setprecision(10), it prints exactly 10 digits after decimal. If we use higher precision, it may not pad with zeros, but setprecision(10) will produce 10 digits after decimal, padding with zeros if needed. So that's good.

    Now, note: For double, sometimes printing with high precision might show rounding artifacts like 2.9999999999 instead of 3.0. But if we compute using double, it should be fine. However, we may want to ensure that for integer roots, we get exact representation. Since we compute with integers and division, some fractions may be exact binary (like 0.5) but many are not. But printing with 10 digits rounding is usually fine. But to avoid 2.9999999999, we could add a small epsilon when printing? Actually the better approach: Use the formula that avoids catastrophic cancellation: For roots, we could compute using high precision: Use long double? But double is enough. For integer roots, the calculation should yield exact integer if using double and the numbers are within representable integer range. For example, (5 - sqrt(1)) / 2 = (5-1)/2 = 4/2 =2. sqrt(1)=1 exactly, 5 and 1 and 2 are exact, so result exactly 2. So okay.

    For D=0 root: -B/(2A). If B and A are integers, the result might be a rational number with terminating binary? Not always, e.g., B=1, A=3 => -1/6 = -0.16666666666666666... but printing with 10 digits will give -0.1666666667 (rounded). That's acceptable.

    Thus solution seems fine.

    Now, double-check infinite root: If all zero, infinite. But what about A=0, B=0, C=0, it's infinite. But there is also case where equation is identity after simplification? For example, 0x^2 + 0x + 0 = 0 is only identity. Could there be something like 0x^2 + 0x + 0 = 0? That's the only. If A=0, B=0, C=0, we printed -1. Good.

    But what about A=0, B=0, C=0? That's correct.

    Now, any scenario where the equation reduces to 0 = 0 for all x even if coefficients not all zero? For example, if A=0, B=0, C=0 only. If A=0, B=0, C=0 is the only. But what about if the quadratic is (x-1)^2 - (x^2-2x+1)=0? Actually that is 0=0? But coefficients would be something like A=0, B=0, C=0? No, if you expand (x-1)^2 - (x^2-2x+1) = 0 -> 0=0. So coefficients are all zero. So again.

    Thus no other.

    Now, we can implement.

    Now, I should think about potential pitfalls: Input can be negative. In discriminant, we need to cast to long long: B*B may overflow for int if B=1e5 => 1e10 > 2^31-1. So use long long multiplication.

    Thus we do: long long A, B, C; cin >> A >> B >> C; (though int would suffice but we need long long for D, but we could store A,B,C as int and cast for D. But it's simpler to use long long.)

    Now, in the linear case, root = -C/(double)B. But if B is negative, division yields positive? No issue.

    Now, for formatting: Once we set fixed and setprecision, all subsequent doubles printed will use that. So we can set once before printing roots.

    Now, careful: In the quadratic D>0 case, we compute x1 and x2 as double. Might get very close values due to cancellation when B and sqrt(D) are close? Example: B large positive, sqrt(D) close to B? Actually if discriminant is close to B^2? That occurs when 4AC is small. For instance, A=1, B=100000, C=0.000? But C is integer, so 4AC=0 => D=B^2 => sqrt(D)=abs(B). So if B positive, sqrt(D)=B. Then roots: (-B - B)/(2A) = -B/A, and (-B+B)/(2A)=0. So no cancellation. If 4AC is small but non-zero, then sqrt(D) ~ B, and then (-B + sqrt(D)) could be small, leading to catastrophic cancellation. For example, A=1, B=100000, C=1? Then D = B^2 - 4AC = 1e10 - 4 = 9999999996, sqrt(D) = sqrt(1e10 - 4). sqrt(1e10) = 100000, sqrt(1e10 - 4) ~ 100000 - 2e-5? Actually compute: sqrt(1e10 - 4) = 100000 * sqrt(1 - 4e-10) ≈ 100000*(1 - 2e-10) = 100000 - 2e-5 = 99999.99998? Wait: Let's compute precisely: (100000 - ε)^2 = 1e10 - 2100000ε + ε^2 = 1e10 - 200000ε + ε^2 ≈ 1e10 - 200000ε. Setting equal to 1e10 -4 gives ε ≈ 4/200000 = 2e-5 = 0.00002. So sqrt(D) ≈ 99999.99998. Then (-B + sqrt(D)) ≈ -100000 + 99999.99998 = -0.00002, which is small, and dividing by 2A yields about -0.00001. That's okay but cancellation causes loss of relative precision; however absolute error might be small. Since we print 10 decimal digits, the value might be accurate enough? The exact root is (-B + sqrt(D))/(2A). We could compute more accurately using alternative formula: x1 = (-B - sqrt(D))/(2A) and x2 = (2C)/(-B - sqrt(D))? Actually for the smaller magnitude root we could use the formula x2 = 2C / (-B - sqrt(D)) to avoid cancellation. But is it necessary? The problem constraints are moderate, and double precision is about 15 decimal digits. For root like 1e-5, we need 10 digits after decimal, so absolute error should be less than 1e-10 maybe. The cancellation might cause relative error but absolute error? Let's analyze: In the expression (-B + sqrt(D)), both terms are about 1e5, difference about 4/(21e5?) Actually from the quadratic formula, the difference between B and sqrt(D) is about 2CA? Hmm.

    We can use the alternative method: For roots x1 and x2, we have x1x2 = C/A (if A !=0). So one root can be computed via the formula that avoids subtraction when B and sqrt(D) have same sign. Standard approach: compute q = -0.5(B + sign(B)*sqrt(D)), then x1 = q/A, x2 = C/q (if q not zero). But easier: we can compute both using double and then print with 10 decimal digits. Given the constraints (coefficients up to 1e5), the roots magnitude could be as large as maybe up to 1e5? Actually if A is small and B large, roots can be large. For example, A=1, B=1e5, C=0 => roots: 0 and -1e5. For the root near 0, computed as (-B + sqrt(D))/(2) where D = B^2 -0 = 1e10, sqrt(D) = 1e5, then -B + sqrt(D) = -1e5 + 1e5 = 0 exactly. So no error. If C is small but not zero, the near-zero root may be computed with cancellation, but the exact value is ~ -C/B? Actually for large B, the smaller magnitude root is approximately -C/B. Indeed, from quadratic: if A=1, B large, C small, the two roots are r1 ≈ -B (large), r2 ≈ -C/B (small). Using the alternative form: r2 = (2C)/(-B - sqrt(D)). Since sqrt(D) ≈ |B| (if B>0, sqrt(D) ≈ B), denominator = -B - sqrt(D) ≈ -2B, so r2 ≈ C/B? Actually r2 = 2C/(-B - sqrt(D)). That avoids cancellation because -B - sqrt(D) is about -2B (two numbers of same sign added). So it's more accurate. But we need to decide if necessary.

    Given typical Codeforces problems (I think this is from Codeforces 168A? Actually might be from Timus? But anyway), they usually accept straightforward double computation, because the constraints and required precision (5 digits) are low enough. However, to be safe, we could implement the stable computation.

    But let's test a worst-case scenario: A=1, B=100000, C=1. Then exact roots? Solve x^2 + 100000 x + 1 = 0. The discriminant D = 100000^2 - 4 = 10000000000 - 4 = 9999999996. sqrt(D) = sqrt(9999999996). The exact roots: x = [-100000 ± sqrt(9999999996)]/2. The larger magnitude root: approx -100000 - 99999.99998? Actually sqrt(D) slightly less than 100000. So -100000 - sqrt(D) ≈ -200000, so large negative root about -199999.99998/2 = -99999.99999. The smaller root: (-100000 + sqrt(D))/2 ≈ ( -100000 + 99999.99998 )/2 = (-0.00002)/2 = -0.00001. So the small root is -1e-5. Now compute with double: B=100000.0, sqrt(D) computed as sqrt(9999999996.0). Let's compute sqrt(9999999996) exactly? 9999999996 is an integer; its square root is not integer. double has 53 bits of mantissa (~16 decimal digits). 9999999996 is about 1e10, so representable exactly? 1e10 is exactly representable? 1e10 in binary is not exact, but double can represent integers up to 2^53 ≈ 9e15 exactly, so 9999999996 is exactly representable as double. Then sqrt(D) will be computed with rounding error, but the sqrt function should return the closest representable double to the exact sqrt. The error in sqrt is at most 0.5 ulp. The ulp of a number around 1e5 is about 1e-10? Actually double precision: for numbers around 1e5, the spacing between representable doubles is about 2^-52 * 1e5 ≈ 2.22e-16 * 1e5 = 2.22e-11. So the error in sqrt could be around that magnitude. So sqrt(D) ≈ exact_sqrt + ε, where |ε| ~ 1e-11. Then computing (-B + sqrt(D)) yields small number about -0.00002 plus ε. The error could be on the order of ε, i.e., 1e-11. Dividing by 2 yields error ~5e-12. So the computed small root may have absolute error ~1e-11, which is far below 1e-10 needed for 10 decimal places after decimal? Actually we need absolute error less than 0.5 * 10^{-10} to guarantee 10 correct digits after decimal? For a number around 1e-5, the digits after decimal are up to maybe 5 digits before decimal? Actually -0.00001 has 5 zeros then 1. To print 10 digits after decimal, we need accurate to 1e-10. Our error ~1e-11 is good. But could there be cases where cancellation leads to larger relative error that translates to larger absolute error? Actually if the two numbers subtract to produce a value that is many orders of magnitude smaller than themselves, the absolute error in the result is about the error in the operands, which is about ulp of the large numbers, which is about 1e-11 for numbers around 1e5. So absolute error in the result is about 1e-11. So it's fine for 10 decimal digits after point. However, if B is up to 1e5, the large numbers are up to 1e5, not larger. If B is 1e5, ulp ~ 1e-11. If B is 1e5, sqrt(D) similar. So absolute error in small root is at most ~1e-11. So printing 10 digits after decimal is safe. But what if A is not 1? Suppose A=1e-5? Actually A can be up to 1e5, but A is integer, can be 0? Actually A can be up to 1e5, positive or negative. The large numbers are B and sqrt(D). B up to 1e5. So the magnitude of the large terms is at most 1e5. But if A is large, then the roots might be small because dividing by large A. For example, A=100000, B=100000, C=1. Then discriminant D = 1e10 - 41000001 = 1e10 - 400000 = 9999600000? Actually 4AC = 41000001 = 400000. So D = 1e10 - 400000 = 9999600000. sqrt(D) ≈ 99998.0? Actually sqrt(1e10)=100000, so sqrt(D) slightly less: sqrt(1e10 - 400000) ≈ 100000 - (400000)/(2*100000) = 100000 - 2 = 99998. So then roots: (-B ± sqrt(D))/(2A) = (-100000 ± 99998)/(200000). So one root: (-100000 - 99998)/200000 = -199998/200000 = -0.99999; the other: (-100000 + 99998)/200000 = -2/200000 = -0.00001. Here both numbers are of moderate size ~1. The cancellation in the numerator for the small root is -2, which is not extremely small relative to the operands (100000). The absolute error in the numerator could be about 1e-11, so the small root error ~1e-11/200000 = 5e-17, which is negligible. So still fine.

    What about A being very small? A could be 1? Already considered. The worst cancellation occurs when B and sqrt(D) are nearly equal and A is 1, giving a very small numerator. The numerator could be as small as about 4AC/(2B)? Actually the difference is (B^2 - (B^2 - 4AC))? Actually sqrt(D) ≈ |B| - (2|AC|/|B|) for large B. So numerator for the root with opposite sign to B is (-B + sign(B)sqrt(D))? If B positive, then -B + sqrt(D) ≈ -B + (B - 2AC/B) = -2AC/B. So magnitude ~ 2|AC|/|B|. The smallest numerator occurs when |AC| is small. Since A and C are integers, minimum |AC| is 0. But if AC=0, then one root is zero exactly. For non-zero, min |AC| >= 1. Then numerator magnitude >= 2/|B|. So minimum absolute value of numerator is about 2e-5 when B=1e5. Dividing by 2A (with A=1) gives root magnitude >= 1e-5. So the smallest root magnitude is about 1e-5, not extremely close to zero (like 1e-10). So absolute error of 1e-11 in numerator yields relative error maybe high, but absolute error in root is ~1e-11/2 ~5e-12. This is still below 1e-10. So 10 decimal digits after decimal means we need absolute error < 5e-11 for rounding to correct? Actually to print correctly to 10 decimal places, we need the number to be accurate to within 5e-11 to get the 10th digit correct. Our error may be around 1e-11, so it should be okay. If we had smaller roots, e.g., B=1e5, A=1, C=1 gives root about -1e-5. That's fine.

    But what if B is 0? Then discriminant = -4AC. But if B=0 and D>0, then roots are ± sqrt(-4AC)/(2A) = ± sqrt(-4AC)/(2A). sqrt(D) is sqrt(4|A*C|). So the two roots are symmetric: x = ± sqrt(|C/A|) maybe. No cancellation.

    Thus straightforward double should suffice.

    Nevertheless, I should be careful about D being computed as long long, and then converting to double for sqrt. For large D up to ~5e10, double can represent exactly integer up to 2^53 ~9e15, so exact. sqrt may not be exact, but that's okay.

    Now, one more nuance: The problem statement says "distinct roots". So if D=0, it's a double root, but we count it as 1 distinct root. So output 1 and that root.

    Now, also note that if A=0 and B=0 and C=0 => infinite, we output -1.

    Edge case: A=0, B=0, C=0 => -1.

    Edge case: A=0, B=0, C=5 => 0.

    Now, let's test some sample cases:

    Input: 0 0 0 => output -1.

    Input: 0 0 5 => 0.

    Input: 0 5 0 => 1 \n 0.0000000000.

    Input: 0 5 10 => 1 \n -2.0000000000.

    Input: 1 -5 6 => as example.

    Input: 2 -8 8 => D=64-64=0 => root 2.0? Actually 2x^2 -8x+8=0 => divide 2: x^2-4x+4=0 => (x-2)^2 => root 2.0. Output 1 \n 2.0000000000.

    Input: 1 0 -1 => D=4 => roots -1,1. Output 2 \n -1.0000000000 \n 1.0000000000.

    Now, check if root ordering: for 1 0 -1, x1 = (0 - sqrt(4))/(2) = -2/2=-1, x2 = (0+2)/2=1. sorted: -1,1. Good.

    Now, check negative A: -1 0 4 => D=16 => roots: (0 -4)/(-2) = 2, (0+4)/(-2)=-2. Sorted: -2,2.

    Our code: x1 = (-0 -4)/(2*-1) = (-4)/(-2)=2, x2 = (0+4)/(-2)=4/(-2)=-2 => unsorted (2, -2). We swap if x1 > x2 => swap => x1=-2, x2=2. Good.

    Now, test with A=1, B=100000, C=1. Should output two roots: approx -99999.99999? Actually large root about -99999.99999? Actually compute precisely: x1 = (-B - sqrt(D))/2 = (-100000 - sqrt(9999999996))/2. sqrt(9999999996) ≈ 99999.99998? Let's compute: sqrt(9999999996) =? Use Python mental? Actually 100000^2 = 10^10. So D = 10^10 - 4. sqrt(D) = sqrt(10^10 - 4). (10^5 - ε)^2 = 10^10 -2*10^5 ε + ε^2 ≈ 10^10 - 200000 ε. Set equal to 10^10 -4 => ε ≈ 4/200000 = 0.00002. So sqrt ≈ 100000 - 0.00002 = 99999.99998. Then large root = (-100000 - 99999.99998)/2 = -199999.99998/2 = -99999.99999. Small root = (-100000 + 99999.99998)/2 = -0.00002/2 = -0.00001. So roots: -99999.99999 and -0.00001. Sorted: -99999.99999, -0.00001. Our computation should produce that. But double precision might represent -99999.99999 exactly? Not exactly but to 10 decimal places, it's fine.

    Now, we need to output with 10 digits after decimal. For -99999.99999, that would be -99999.9999900000? Actually -99999.99999 has 5 digits after decimal? Wait, -99999.99999 has 5 digits after decimal? It has 5 digits: 99999.99999 (5 digits after decimal). But we need at least 5, so we output 10 digits: -99999.9999900000? We need to print exactly 10 digits after decimal. So -99999.99999 would be printed as -99999.9999900000 if we setprecision(10)? Let's compute: -99999.99999 as double may be -99999.9999900000? Actually -99999.99999 is -99999.99999 exactly? But double cannot represent exactly, so it will be approximated. However, printing with 10 decimal places will show something like -99999.9999899999 perhaps. But it should be within rounding. The problem only requires at least 5 digits after decimal, not exact value. So it's acceptable.

    But to be precise, we might want to ensure that the root is printed correctly rounded. Usually Codeforces accepts such solutions.

    Now, potential issue: When D is a perfect square and A is negative, we might get -0.0 for root if it's exactly zero? Example: A=-1, B=0, C=0 => D=0 => root = -0/( -2 ) = 0.0. But -0/( -2) yields 0.0, not -0.0. But if we compute -double(B)/(2A) = -0.0 / -2 = 0.0? Actually -0.0 is negative zero, but dividing by negative yields positive zero? In C++, -0.0 / negative yields +0.0? Let's test: double B = 0; double A = -1; double root = -B / (2A); -B = -0.0 => -0.0, which is negative zero. Then dividing by (2*A) which is -2 yields positive zero. So root = 0.0. So no issue. But if we compute for linear case: B= -0? Actually B is integer so no negative zero. So fine.

    Now, we need to make sure that for D>0 case, we set precision before printing.

    Now, let's also consider that we might output "0" for no roots, but "0" is an integer, not "0.0000000000". That's correct.

    Now, infinite case prints "-1".

    Now, implement.

    But wait: There is a nuance: If A=0 and B=0 and C=0, infinite. However, what about A=0, B=0, C=0? Yes.

    What about A=0, B=0, C=0 but also some other cases? Already covered.

    Now, I think the solution is correct.

    But let's double-check problem statement: "Ax2 + Bx + C = 0." Possibly it's "A x^2 + B x + C = 0". So yes.

    Now, let's consider potential tricky case: A != 0, but the equation reduces to linear? No, it's quadratic unless A=0.

    Now, also consider the case where A != 0 but after simplification (e.g., if B^2 - 4AC = 0) it's a double root.

    Now, also consider that roots might be equal but we only print distinct. So D=0 => one root.

    Now, I'm satisfied.

    But maybe the problem expects output of roots exactly as rational if they are integers? But it's fine.

    Now, I'll produce the final answer in C++.

    Now, also ensure that we include for sqrt and fabs, for setprecision, for swap (or we can just use std::swap but we can do manual swap).

    Now, code:

    #include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    
    int main() {
        long long A, B, C;
        cin >> A >> B >> C;
    
        if (A == 0 && B == 0 && C == 0) {
            cout << -1 << endl;
            return 0;
        }
    
        if (A == 0) {
            if (B == 0) {
                cout << 0 << endl;
            } else {
                double root = -double(C) / B;
                if (fabs(root) < 1e-12) root = 0.0;
                cout << 1 << endl;
                cout << fixed << setprecision(10) << root << endl;
            }
            return 0;
        }
    
        // A != 0
        long long D = B * B - 4LL * A * C;
        if (D < 0) {
            cout << 0 << endl;
        } else if (D == 0) {
            double root = -double(B) / (2.0 * A);
            if (fabs(root) < 1e-12) root = 0.0;
            cout << 1 << endl;
            cout << fixed << setprecision(10) << root << endl;
        } else {
            double sqrtD = sqrt((double)D);
            double x1 = (-double(B) - sqrtD) / (2.0 * A);
            double x2 = (-double(B) + sqrtD) / (2.0 * A);
            if (x1 > x2) swap(x1, x2);
            if (fabs(x1) < 1e-12) x1 = 0.0;
            if (fabs(x2) < 1e-12) x2 = 0.0;
            cout << 2 << endl;
            cout << fixed << setprecision(10) << x1 << endl;
            cout << fixed << setprecision(10) << x2 << endl;
        }
    
        return 0;
    }
    

    But need to include for sqrt and fabs. Use for setprecision. Good.

    Now, one more nuance: In the linear case, if B != 0, but what if both B and C are zero? Then root = 0.0. That's fine. And we output 1 root.

    Now, check: A=0, B=5, C=0 => root=0 => 1 and 0.0000000000.

    Now, also check: A=0, B=-3, C=0 => root = 0 => same.

    Now, what about A=0, B=2, C=3 => root = -1.5 => output 1 and -1.5000000000.

    Now, for quadratic with D>0 but A negative, we sort.

    Now, I'll test with a case where root is exactly -0.0 due to computation: A=1, B=0, C=0 => D=0 root=0.0. Good.

    Now, case: A=1, B=2, C=1 => root = -1.0.

    Now, all good.

    But note: The problem says "print all of them in ascending order". For two roots, we already sorted.

    Now, potential issues: If D > 0 but the two roots are equal due to floating error? Not likely because D>0 ensures distinct real roots. But double might compute them as equal if D is extremely small? D is integer at least 1, because D > 0 integer, so difference between roots is sqrt(D)/(A) in magnitude. For integer A and D>=1, the roots are distinct. Even if A is huge, the difference could be as small as about sqrt(1)/A which could be as small as 1/1e5 = 1e-5, which is still above double precision? Actually double can represent differences down to about 1e-16 relative, so 1e-5 is fine. So they will be distinct in double.

    Now, we must output exactly 2 roots.

    Now, let's also consider the possibility that we might need to handle the case where A is 0 but B is not 0, and we print the root. This is fine.

    Now, test with sample: Input: 1 -5 6 -> output 2 and 2.0000000000 and 3.0000000000.

    Now, one more test: Input: 0 0 1 -> output 0.

    Input: 0 0 0 -> -1.

    Input: 0 2 4 -> 1 and -2.0000000000.

    Works.

    Now, ensure that we use long long for discriminant. However, A, B, C are within [-1e5, 1e5], so B^2 up to 1e10, 4AC up to 4e10, D up to 5e10, fits in long long (which is at least 64-bit). Good.

    Now, double-check if we need to handle the case where A and B are both zero but C is zero? Already handled as infinite.

    Now, also note: The problem says "any coefficient may be equal to 0". So our handling is correct.

    Now, I think this is correct.

    But let's also consider that if A=0 and B=0 and C=0 => infinite => -1. Good.

    Now, maybe there is an alternative interpretation: "infinite root count" could also happen if equation reduces to identity, like 0x^2 + 0x + 0 = 0, which we have. Also if both A and B are zero and C=0, then any x works. So yes.

    Now, I think the solution is complete.

    Now, I'll produce final answer.

    But wait: In the quadratic D=0 case, we output 1 root. But should we consider if the root is double (two equal roots) but still distinct? The problem says "distinct roots", so 1.

    Now, one more nuance: When A != 0, if C=0 and B=0, then root x=0 (double). D=0? Actually B=0, C=0 => D=0 => root 0. So one distinct root.

    Now, output as required.

    Now, maybe there is case where A=0, B=0, C=0 infinite; but also if A=0, B=0, C=0 is the only infinite case.

    Now, confirm that we printed with setprecision(10) and fixed. This prints 10 digits after decimal. For integer roots, it prints .0000000000. Good.

    Now, double-check that we reset precision for all root outputs. We set it each time before printing. Could set once at top after reading.

    Now, final code.

    But note: In the linear case, we need to output 1 and root. In quadratic case we output 2 and roots. In D=0, output 1 and root.

    Now, one more thing: In the case where A != 0 and D > 0, we sort x1, x2. But after sorting, we need to ensure they are printed in ascending order. Good.

    Now, check for negative zero: We use fabs < 1e-12 to set to 0.0. Is 1e-12 enough? For roots that are truly 0 but computed as 1e-15 due to rounding? Could happen if root is exactly 0 but due to floating errors we get something like -1e-16? For example, if A=1, B=0, C=0 -> root = -0.0/(2) = 0.0 exactly? Actually double arithmetic: -double(B) = -0.0, dividing by 2A = 2 gives -0.0? Let's compute: B=0 as int, double(B)=0.0, -double(B) = -0.0. 2A = 2, so -0.0/2 = -0.0? Actually division of -0.0 by positive 2 yields -0.0. So root could be -0.0. But -0.0 is a double with sign bit negative. fabs(-0.0) is 0.0, so less than 1e-12 -> set to 0.0. So that works. For other cases where root is extremely small but not zero, like 1e-10, setting to 0.0 would be wrong. But typical roots near zero could be like -1e-10? Could that happen? Possibly if coefficients are such that root is very small, e.g., A=1, B=100000, C=0.000001? But C is integer, so smallest non-zero C is 1. With B=1e5, A=1, the small root magnitude is |C/B| = 1e-5. So root magnitude is at least 1e-5 if B != 0 and C != 0 and A=0? Actually for linear case: root = -C/B, with B up to 1e5, C up to 1e5, smallest non-zero magnitude is min(|C|/max(|B|) when C !=0 and B !=0. But if B is large, C=1 gives root = -1/100000 = 1e-5. So minimal magnitude is about 1e-5. So threshold 1e-12 is safe. For quadratic, the smallest non-zero root magnitude might be even smaller? Consider A=1, B=100000, C=1 gave root about -1e-5. For other combinations? Let's try to find smallest possible non-zero root magnitude. For quadratic, roots are given by [-B ± sqrt(D)]/(2A). The difference between roots can be small if D is small but positive. D is integer >=1. So sqrt(D) >= 1. For given A, the smallest non-zero root magnitude might be when the numerator is small. The numerator can be as small as? For the root with opposite sign: (-B + sqrt(D)) if B positive, sqrt(D) is slightly less than B if 4AC > 0? Actually D = B^2 - 4AC. For that root to be near zero, we need -B + sqrt(D) ≈ 0 => sqrt(D) ≈ B => D ≈ B^2 => 4AC ≈ 0 => either A or C near zero? But if A and C are integers, the smallest non-zero difference occurs when |4AC| is minimal non-zero, which is 411 = 4. Then D = B^2 - 4. For large B, sqrt(D) = B * sqrt(1 - 4/B^2) ≈ B*(1 - 2/B^2) = B - 2/B. Actually more precisely: sqrt(B^2 - 4) = B * sqrt(1 - 4/B^2) ≈ B * (1 - 2/B^2 - ...) = B - 2/B - ... So -B + sqrt(D) ≈ -2/B. Then root = (-2/B)/(2A) = -1/(A B). So magnitude ≈ 1/(|A|B). With |A| >=1, |B| up to 1e5, so magnitude could be as small as 1/(1e51e5) = 1e-10? Wait A could be up to 1e5, B up to 1e5, product up to 1e10, so root magnitude as small as 1e-10. But is that possible? Let's explore: For the root x_small = (-B + sqrt(B^2 - 4AC))/(2A). Assume B > 0, A > 0, and C positive? Actually sign of AC influences. For the numerator to be small, we need B and sqrt(D) close. That happens when 4AC is positive and small? D = B^2 - 4AC. For sqrt(D) to be close to B, we need 4AC positive and small. Since A and C are integers, smallest positive 4AC is 4 if A=1, C=1 or A=-1, C=-1 (so product positive). But 4AC must be positive? Actually D = B^2 - 4AC, so for sqrt(D) < B, we need 4AC > 0. That means A and C have same sign. So both positive or both negative. If both are 1, then 4AC = 4. So D = B^2 - 4. Then numerator ≈ -B + (B - 2/B) = -2/B. So x_small ≈ (-2/B)/(2A) = -1/(A B). So magnitude ≈ 1/(A B). To minimize this, we want A and B as large as possible, both up to 1e5, so minimal magnitude ≈ 1/(1e5 * 1e5) = 1e-10. Also if A and B are both positive large, root is about -1e-10. That's non-zero but smaller than 1e-12? Actually 1e-10 > 1e-12. So threshold 1e-12 is safe: roots that are truly zero will be exactly zero only when the mathematical value is zero. Could a mathematically non-zero root be less than 1e-12? Possibly if A and B are larger than 1e5? But constraints limit them to 1e5. The product AB max is 1e10, so 1/(A B) min is 1e-10. So no root smaller than 1e-10 in absolute value, except zero exactly. However, what about linear case? root = -C/B. min non-zero magnitude: when |C|=1, |B|=1e5 => 1e-5, larger. So safe. Therefore threshold 1e-12 is safe to catch floating -0.0 without accidentally zeroing genuine small roots.

    But note: If A and B are both 1e5, then root ≈ -1/(1e10) = -1e-10. That's > 1e-12. So safe. If one is negative, magnitude similar. So threshold 1e-12 is fine.

    Now, I'll produce final answer.

    But we also need to consider if the output should have trailing zeros exactly like sample? The sample prints "2.0000000000" i.e., 10 digits after decimal. So setprecision(10) is appropriate.

    Now, potential problem: In some compilers, double may have less precision, but it's standard 64-bit double.

    Now, note: In quadratic D>0 case, we used double sqrt(D). For D up to 5e10, sqrt(D) up to ~2.2e5, fine.

    Now, maybe we should also consider the case where A != 0 and D is a perfect square and the roots are rational. That's fine.

    Now, final code.

    But we need to include <bits/stdc++.h>? Usually on Codeforces they accept iostream, cmath, iomanip. But using bits/stdc++.h is okay.

    I'll produce final answer.

    One more nuance: The problem says "Your task is to find the number of distinct roots of the equation and print all of them in ascending order." So for quadratic with D=0, one distinct root, we print it. That's fine.

    Now, what about if A != 0 and D > 0 but the two roots are not sorted automatically due to sign? We sort.

    Now, also, the problem says "Print roots with at least 5 digits after the decimal point." So 10 digits is okay.

    Now, finalize.

    Now, I'll write the final solution.

    I think that's correct.

    But I recall there is a known Codeforces problem "Quadratic equation" maybe. And some edge cases: When A=0 and B=0 and C=0 => infinite; A=0 and B=0 and C!=0 => no roots; else if A=0 and B!=0 => one root; else quadratic. They also consider that if A=0 and B=0 and C=0 => infinite; else if A=0 and B=0 => no roots; else if A=0 => linear. So same as mine.

    But wait: There is also a tricky case: A=0, B=0, C=0 => infinite; but also what about A=0, B=0, C=0? Covered.

    Now, ensure to output -1 as integer and not as double.

    Now, final code.

    Potential improvement: Use long double for more precision? Not necessary.

    Now, I'll produce answer.

    But there is also a case where A and B are both zero but C != 0: no roots.

    Now, okay.

    Now, also consider if input values are large, but we use double for root calculation, and we have to be careful about possible overflow when computing double(B) for large B? B up to 1e5, fine.

    Now, finalize.

    One more thing: In the quadratic case, if A is negative, denominator negative, but sorting solves ordering.

    Now, I will include comments? Not necessary.

    Now, produce final output.

    Thus the solution. ```cpp

    #include #include #include #include

    using namespace std;

    int main() { long long A, B, C; cin >> A >> B >> C;

    // infinite solutions
    if (A == 0 && B == 0 && C == 0) {
        cout << -1 << endl;
        return 0;
    }
    
    // linear (or degenerate)
    if (A == 0) {
        if (B == 0) {          // C != 0 guaranteed by previous check
            cout << 0 << endl;
        } else {
            double root = -double(C) / B;
            if (fabs(root) < 1e-12) root = 0.0;
            cout << 1 << endl;
            cout << fixed << setprecision(10) << root << endl;
        }
        return 0;
    }
    
    // quadratic
    long long D = B * B - 4LL * A * C;
    if (D < 0) {
        cout << 0 << endl;
    } else if (D == 0) {
        double root = -double(B) / (2.0 * A);
        if (fabs(root) < 1e-12) root = 0.0;
        cout << 1 << endl;
        cout << fixed << setprecision(10) << root << endl;
    } else {
        double sqrtD = sqrt(double(D));
        double x1 = (-double(B) - sqrtD) / (2.0 * A);
        double x2 = (-double(B) + sqrtD) / (2.0 * A);
        if (x1 > x2) swap(x1, x2);
        if (fabs(x1) < 1e-12) x1 = 0.0;
        if (fabs(x2) < 1e-12) x2 = 0.0;
        cout << 2 << endl;
        cout << fixed << setprecision(10) << x1 << endl;
        cout << fixed << setprecision(10) << x2 << endl;
    }
    
    return 0;
    

    }