123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- //我是个傻逼
- #include <iostream>
- //我是个傻逼
- #include <math.h>
- using namespace std;
- int main()
- {
- double a,b,c,a2,a21,b1,x1,x2,gdelta,delta1,mum,den,mum1,den1;
- int qu=1,delta,delta2;
- cout<<"������a��b��c"<<endl;
- cin>>a>>b>>c;//����ϵ��
- cout<<a<<"x^2+"<<b<<"x+"<<c<<"=0"<<endl;
- delta=delta1=(b*b)-(4*a*c);
- cout<<"delta="<<delta<<endl;
- if (delta>=0&&(b*b)-(4*a*c)==floor((b*b)-(4*a*c)))//�жϦ��Ƿ�>=0�Լ��Ƿ�������
- {
- gdelta=sqrt(delta);
- if (gdelta==floor(gdelta))//�жϸ����¦��Ƿ�������
- {
- x1=(-b+gdelta)/(2*a);
- x2=(-b-gdelta)/(2*a);
- if (x1==floor(x1)&&x2==floor(x2))//�жϽ��Dz�������
- {
- cout<<"x1="<<x1<<"\nx2="<<x2<<endl;
- }
- else
- {
- mum=-b+gdelta;
- den=2*a;
- for (int j = 2; j<=fabs(mum)&&j<=fabs(den); j++)
- {
- mum1=mum/j;
- den1=den/j;
- if (mum1==floor(mum1)&&den1==floor(den1))
- {
- mum=mum1;den=den1;
- j=j-1;
- }
- }
- cout<<"x1="<<mum<<"/"<<den<<endl;
- mum=-b-gdelta;
- den=2*a;
- for (int j = 2; j<=fabs(mum)&&j<=fabs(den); j++)
- {
- mum1=mum/j;
- den1=den/j;
- if (mum1==floor(mum1)&&den1==floor(den1))
- {
- mum=mum1;den=den1;
- j=j-1;
- }
- }
- cout<<"x2="<<mum<<"/"<<den<<endl;
- }
- }
- else
- {
- delta2=delta;
- for(int i=2;i<=delta;i++)
- {
- int cnt=0;
- while(delta!=i)
- {
- if(delta%i==0)
- {
- cnt++;
- delta=delta/i;
- delta2=delta2/i;
- }
- else break;
- }
- if(i==delta)
- {
- cnt++;
- delta=delta/i;
- delta2=delta2/i;
- }
- if(cnt!=0)
- {
- if (cnt%2==0)
- {
- qu=qu*pow(i,cnt/2);
- }
- if (cnt%2!=0)
- {
- qu=qu*pow(i,(cnt-1)/2);
- delta2=delta2*i;
- }
- }
- }//������
- a2=2*a;
- for (int j = 2; j<=fabs(a2)&&j<=fabs(b)&&j<=fabs(qu); j++)
- {
- a21=a2/j;
- b1=b/j;
- if (qu%j==0&&b1==floor(b1)&&a21==floor(a21))
- {
- qu=qu/j;a2=a21;b=b1;
- j=j-1;
- }
- }//����
- cout<<"x1=("<<-b<<"+"<<qu<<"*sqrt("<<delta2<<"))/"<<a2<<"\nx2=("<<-b<<"-"<<qu<<"*sqrt("<<delta2<<"))/"<<a2<<endl;
- }
- }
- else if (delta>=0)
- {
- gdelta=sqrt(delta1);
- cout<<"delta="<<delta1<<endl;
- x1=(-b+gdelta)/(2*a);
- x2=(-b-gdelta)/(2*a);
- cout<<"x1="<<x1<<"\nx2="<<x2<<endl;
- }//�������С���Ļ���������⣨���˼������ޣ�
- else
- {
- cout<<"������ʵ����"<<endl;
- }
- system("pause");
- return 0;
- }
|