解法一、公式解
🔹 公式
✅ 完整代碼
評分結果(參考) : AC (3ms, 340KB)
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b, c;
    cin >> a >> b >> c;
    int b2_4ac = b*b - 4*a*c;
    if(b2_4ac > 0){
        cout << "Two different roots x1=" <<  (-b + sqrt(b2_4ac))/2/a 
                            << " , x2=" << (-b - sqrt(b2_4ac))/2/a;
    }
    else if(b2_4ac == 0){
        cout << "Two same roots x=" << (-b)/2/a;
    }
    else{
        cout << "No real root";
    }
    return 0;
}