結果
問題 | No.955 ax^2+bx+c=0 |
ユーザー |
|
提出日時 | 2023-07-18 15:56:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,476 bytes |
コンパイル時間 | 847 ms |
コンパイル使用メモリ | 99,520 KB |
最終ジャッジ日時 | 2025-02-15 15:35:11 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 108 WA * 14 |
ソースコード
#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); } double f(ll n){ const int N=100; double lb=0,ub=n+1; for(int t=0;t<N;t++){ double mid=(lb+ub)/2; if(mid*mid<=n){ lb=mid; }else{ ub=mid; } } return lb; } void print(double x){ printf("%.23f\n",x); } 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; // ll g=gcd(b,c); // b/=g; // c/=g; { ll g=1; for(ll t=1;t*t<=min({b,c});t++ ){ if(b%t==0 && c%t==0){ g=t; } } b/=g; c/=g; } double x=-1.0*c/b; //printf("%.12f\n",x); print(x); } return 0; } //ll g=gcd(c,gcd(b,a)); { ll g=1; for(ll t=1;t*t<=min({a,b,c});t++ ){ if(a%t==0 && b%t==0 && c%t==0){ g=t; } } 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("%.12f\n",x); print(x); }else if(D>0){ double x1=(1.0*(-b)-sqrt(D))/(2*a); //double x2=(1.0*(-b)+sqrt(D))/(2*a); double x2=c/(a*x1); //double x1=(1.0*(-b)-f(D))/(2*a); //double x2=(1.0*(-b)+f(D))/(2*a); x1=min(x1,x2); x2=max(x1,x2); cout<<2<<endl; //printf("%.12f\n",x1); //printf("%.12f\n",x2); print(min(x1,x2)); print(max(x1,x2)); }else{ //D<0 //虚数解 cout<<0<<endl; } }