結果

問題 No.955 ax^2+bx+c=0
ユーザー HIcoderHIcoder
提出日時 2023-07-18 15:31:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,343 bytes
コンパイル時間 1,001 ms
コンパイル使用メモリ 96,948 KB
最終ジャッジ日時 2025-02-15 15:34:10
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 69 WA * 53
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=1e9+7;

ll gcd(ll x,ll y){
    return y==0?x:gcd(y,x%y);
}

int main(){
    ll a,b,c;
    cin>>a>>b>>c;

    if(a==0){

        if(b==0){
            if(c==0){
                //a=b=c=0
                //解xは∞個
                cout<<-1<<endl;
            }else{
                //a=b=0, c!=0
                //解なし
                cout<<0<<endl;
            }
        }else{
            //b!=0
            // bx+c=0
            cout<<1<<endl;
            double x=-1.0*c/b;
            printf("%.10f\n",x);

        }
        
        return 0;
    }

    ll g=gcd(gcd(a,b),c);
    a/=g;
    b/=g;
    c/=g;

    if(a<0){
        a*=(-1);
        b*=(-1);
        c*=(-1);
    }

    //a!=0

    ll D=b*b-4*a*c;

    if(D==0){
        cout<<1<<endl;
        double x=1.0*(-b)/2*a;
        printf("%.10f\n",x);
    }else if(D>0){
        double x1=(1.0*(-b)-sqrt(D))/(2*a);
        double x2=(1.0*(-b)+sqrt(D))/(2*a);
        cout<<2<<endl;
        printf("%.10f\n",x1);
        printf("%.10f\n",x2);
    }else{
        cout<<0<<endl;
    }
}
0