HDU 5974 A Simple Math Problem (数论+解方程组)
来源:互联网 发布:淘宝快速备案注销 编辑:程序博客网 时间:2024/06/07 16:00
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
是已知的,求 X、Y
。
思路
无意间自己想出的一个定理(虽然不知道数论里面有没有它),
关于证明在比赛的时候还没有,只是感觉它是对的,可能是数学方面的感性吧~
证明过程:
首先有
我们令
又因为
于是这样便证明成功啦~ (只是还不知道它在什么情况下才会成立)
有了
然后因为
与 X、Y
。
解不存在的情况: X、Y
计算其最小公倍数如果不等于 b
,则解不存在。
AC 代码
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<cmath>#include<iostream>using namespace std;#define MAXX 110000typedef __int64 LL;LL gcd(LL a,LL b){ if(b==0)return a; return gcd(b,a%b);}void solve(int a,int b){ LL gc=gcd(a,b); LL xy=b*gc; LL x_y=sqrt(a*a-4.0*xy); LL x=(a+x_y)/2; LL y=a-x; if(x/gcd(x,y)*y!=b) { printf("No Solution\n"); return; } if(x>y)swap(x,y); printf("%I64d %I64d\n",x,y);}int main(){ LL a,b; while(~scanf("%I64d%I64d",&a,&b)) solve(a,b); return 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 数论 gcd
- HDU 5974 A Simple Math Problem (数论,大连区域赛)
- ACM-ICPC Asia Regional Contest 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
- Oracle 面试题 (三)
- Oracle 面试题 (四)
- Oracle 面试题(二)
- css网站制作流程
- 如何查看执行计划
- HDU 5974 A Simple Math Problem (数论+解方程组)
- SQL_Trace的使用
- tkprof用法
- Linux下修改PATH路径
- 微信小程序学习笔记
- Crontab用法
- 关于alter database open resetlog…
- 从keras看VGG16结构图
- 80行Python实现-HOG梯度特征提取