1. 程式人生 > >大連CCPC D - A Simple Math Problem

大連CCPC D - A Simple Math Problem

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
ll gcd(ll a,ll b){
  return a%b==0?b:gcd(b,a%b);
}
int main(){
  ll a,b;
  ll ans1,ans2;
  while(~scanf("%lld%lld",&a,&b))
  {
    ll g=gcd(a,b);

     
int flag=0; if (a*a-4*b*g<0){ flag=1; }else { ll sq=a*a-4*b*g; ll tmp=sqrt(sq); if (tmp*tmp!=sq){ flag=1; }else { ll fz1=a+(ll)tmp; ll fz2=a-(ll)tmp; if(fz1%2==1 || fz2%2==1){ flag=1; }
else { ans1=fz1/2; ans2=fz2/2; } } } if(flag)printf("No Solution\n"); else printf("%lld %lld\n",min(ans1,ans2),max(ans1,ans2)); } return 0; }