HDU 5974 A Simple Math Problem 数学
来源:互联网 发布:网络共享硬盘无法访问 编辑:程序博客网 时间:2024/06/05 10:36
A Simple Math Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2505 Accepted Submission(s): 777
Problem Description
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
Input
Input 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.
Output
For 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 8798 10780
Sample Output
No Solution308 490
一道纯的数学题。
题意:给出两个数 a,b。a是x和y的和,b是x和y的最小公倍数;
在这里根据两个数互质,则他们的和与他们的积也互质可以推导出a和b的最大公因数就是x和y的最大公因数。
然后解方程,在这里注意一下,求得的解必须是整数。
#include<stdio.h>#include<math.h>#define ll long longusing namespace std;ll gcd(ll a,ll b){ while(b!=0) {ll c=a%b; a=b; b=c; } return a;}ll lcm(ll a,ll b){ return a/gcd(a,b)*b;}int main(){ ll a,b; while(scanf("%lld%lld",&a,&b)!=EOF) { ll c=gcd(a,b); c=b*c; ll d=a-sqrt(a*a-4*c); ll p=d/2; if(a*a-4*c<0) printf("No Solution\n"); else { ll z=a*a-4*c; ll s=sqrt(z); if(s*s==z&&p*2==d) printf("%lld %lld\n",p,a-p); else printf("No Solution\n"); } }}
阅读全文
0 0
- HDU 5974 A Simple Math Problem 数学
- HDU 5974 A Simple Math Problem (数学)
- HDU-5974 A Simple Math Problem(数学)
- HDU 5974 A Simple Math Problem (数学)
- HDU 5974 A Simple Math Problem(简单数学)
- hdu 5974 A Simple Math Problem
- hdu 5974 A Simple Math Problem
- hdu 5974 A Simple Math Problem
- HDU 5974 A Simple Math Problem(数论)
- hdu 5974 A Simple Math Problem
- hdu 5974 A Simple Math Problem
- hdu 5974 A Simple Math Problem
- hdu 5974 A Simple Math Problem
- HDU 5974 A Simple Math Problem
- hdu 5974 A Simple Math Problem
- hdu 5974 A Simple Math Problem
- HDU 5974 A Simple Math Problem
- HDU-5974-A Simple Math Problem
- 阶梯博弈-HDU3389
- zookeeper 配置启动报错(org.apache.zookeeper.server.quorum.QuorumPeerMain)
- SpringBoot自动配置
- Docker
- ECMAScript 2016 (ES7)
- HDU 5974 A Simple Math Problem 数学
- leetcode[Array Partition I]//待整理多种解法
- android 签名打包时去掉log日志打印(仅在debug包中打印log信息)
- Spring学习(四)-Bean的三种装配方式
- 【百度之星】Chess
- ios 网络请求和数据库一起封装,block回调
- request获取数据流
- android RXJava2.0(二)--线程控制
- python学习笔记(三)