码迷,mamicode.com
首页 > 其他好文 > 详细

解方程搞搞

时间:2019-10-26 22:52:38      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:sub   min   gis   swa   fstream   style   mem   class   upper   

题意:http://acm.hdu.edu.cn/showproblem.php?pid=5980

b乘以GCD(a,b)之后,解方程就行了。

  1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
  2 #include <cstdio>//sprintf islower isupper
  3 #include <cstdlib>//malloc  exit strcat itoa system("cls")
  4 #include <iostream>//pair
  5 #include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
  6 #include <bitset>
  7 //#include <map>
  8 //#include<unordered_map>
  9 #include <vector>
 10 #include <stack>
 11 #include <set>
 12 #include <string.h>//strstr substr
 13 #include <string>
 14 #include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
 15 #include <cmath>
 16 #include <deque>
 17 #include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
 18 #include <vector>//emplace_back
 19 //#include <math.h>
 20 #include <cassert>
 21 //#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
 22 #include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
 23 using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
 24 //******************
 25 int abss(int a);
 26 int lowbit(int n);
 27 int Del_bit_1(int n);
 28 int maxx(int a,int b);
 29 int minn(int a,int b);
 30 double fabss(double a);
 31 void swapp(int &a,int &b);
 32 clock_t __STRAT,__END;
 33 double __TOTALTIME;
 34 void _MS(){__STRAT=clock();}
 35 void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
 36 //***********************
 37 #define rint register int
 38 #define fo(a,b,c) for(rint a=b;a<=c;++a)
 39 #define fr(a,b,c) for(rint a=b;a>=c;--a)
 40 #define mem(a,b) memset(a,b,sizeof(a))
 41 #define pr printf
 42 #define sc scanf
 43 #define ls rt<<1
 44 #define rs rt<<1|1
 45 typedef vector<int> VI;
 46 typedef long long ll;
 47 const double E=2.718281828;
 48 const double PI=acos(-1.0);
 49 //const ll INF=(1LL<<60);
 50 const int inf=(1<<30);
 51 const double ESP=1e-9;
 52 const int mod=(int)1e9+7;
 53 const int N=(int)1e6+10;
 54 ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
 55 
 56 int main()
 57 {
 58     ll a,b;
 59     while(~sc("%lld%lld",&a,&b))
 60     {
 61         ll G=GCD(a,b);
 62         b*=G;
 63         if(a*a<4*b)
 64         {
 65             pr("No Solution\n");
 66             continue;
 67         }
 68         ll ans=(-a+(ll)sqrt(a*a-4*b))/(-2);
 69         if(-ans*ans+ans*a-b==0)
 70         {
 71             if(ans<0||a-ans<0)
 72             {
 73                 pr("No Solution\n");
 74             }
 75             else
 76             {
 77                 pr("%lld %lld\n",ans,a-ans);
 78             }
 79         }
 80         else
 81             pr("No Solution\n");
 82     }
 83     return 0;
 84 }
 85 
 86 /**************************************************************************************/
 87 
 88 int maxx(int a,int b)
 89 {
 90     return a>b?a:b;
 91 }
 92 
 93 void swapp(int &a,int &b)
 94 {
 95     a^=b^=a^=b;
 96 }
 97 
 98 int lowbit(int n)
 99 {
100     return n&(-n);
101 }
102 
103 int Del_bit_1(int n)
104 {
105     return n&(n-1);
106 }
107 
108 int abss(int a)
109 {
110     return a>0?a:-a;
111 }
112 
113 double fabss(double a)
114 {
115     return a>0?a:-a;
116 }
117 
118 int minn(int a,int b)
119 {
120     return a<b?a:b;
121 }

 

解方程搞搞

标签:sub   min   gis   swa   fstream   style   mem   class   upper   

原文地址:https://www.cnblogs.com/--HPY-7m/p/11745671.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!