zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    一文告诉你,为什么要研究JVM原理
    高并发中使用到的RateLimiter源码解析
    WEB应用服务架构的演变(扫盲)
    网上安全方面的涉及到的方面(详解)
    JDK安装
    JDKJRKSDK的区别
    本地同时安装oracle客户端与服务端的注意事项
    WMS不同货主的货如何管理
    LeetCode 101
    WMS一物一码、唯一码
  • 原文地址:https://www.cnblogs.com/Annetree/p/7612460.html
Copyright © 2011-2022 走看看