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 }
  • 相关阅读:
    Django重新构造User模型
    在docker中添加mysql在通过远程机器的访问
    php基础笔记
    mysql基础笔记整理
    redis的配置安装与使用
    c++实现对两个有序链表的连接
    java的网络编程(TCP)
    无心制作
    nacos配置服务
    声明式远程调用OpenFeign(微服务调用微服务)
  • 原文地址:https://www.cnblogs.com/Annetree/p/7612460.html
Copyright © 2011-2022 走看看