• 2016ICPC-大连 A Simple Math Problem (数学)


    Given two positive integers a and b,find suitable X and Y to meet the conditions:
    X+Y=a
    Least Common Multiple (X, Y) =b
    InputInput includes multiple sets of test data.Each test data occupies one line,including two positive integers a(1≤a≤2*10^4),b(1≤b≤10^9),and their meanings are shown in the description.Contains most of the 12W test cases.OutputFor each set of input data,output a line of two integers,representing X, Y.If you cannot find such X and Y,output one line of "No Solution"(without quotation).Sample Input

    6 8
    798 10780

    Sample Output

    No Solution
    308 490

    设gcd(x,y)=u,x=m*u,y=n*u
    a/b=(mu+nu)/(m*n*u)
    化简一下可以求出m,n,从而求出X,Y

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<string>
     6 #include<queue>
     7 #include<vector>
     8 #include<cmath>
     9 using namespace std;
    10 const double pi=acos(-1.0);
    11 int n,d,x;
    12 long long a,b,u;
    13 long long gcd(long long a,long long b)
    14 {
    15     if (b==0) return a;
    16      else return gcd(b,a%b);
    17 }
    18 int main()
    19 {
    20      while(~scanf("%lld%lld",&a,&b))
    21      {
    22          u=gcd(a,b);
    23          a=a/u;
    24          b=b/u;
    25          if ( (long long)sqrt(a*a-4*b)*(long long)sqrt(a*a-4*b)==a*a-4*b )
    26          {
    27              long long t=(long long)sqrt(a*a-4*b);
    28              if ((a+t)%2==0 && a>t) printf("%lld %lld
    ",u*(a-t)/2,u*(a+t)/2);
    29               else printf("No Solution
    ");
    30          } else printf("No Solution
    ");
    31      }
    32     return 0;
    33 }
  • 相关阅读:
    K&R C C90,C99的改进
    Windows 用来定位 DLL 的搜索路径
    常量字符串的问题
    C++0x中一些有用的新特性
    mainfest机制
    mainfest机制
    C++0x中一些有用的新特性
    c语言目标程序中的段
    c语言目标程序中的段
    数据模型(LP32 ILP32 LP64 LLP64 ILP64 )
  • 原文地址:https://www.cnblogs.com/Annetree/p/7612460.html
Copyright © 2020-2023  润新知