HDU 5974 A Simple Math Problem (解方程)
题意:给定a和b,求一组满足x+y=a && lcm(x, y)=b。
析:x+y = a, lcm(x, y) = b,=>x + y = a, x * y = b * k,其中 k = gcd(x, y)。
然后第一个式子同时除以k,第二个式子同时除以k*k,那么x/k,和y/k是互质的,那么a/k和b/k也是互质的。所以问题就转化成了
x' + y' = a',x' * y' = b'。然后解方程并判断解的存在即可。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} int main(){
int a, b;
while(scanf("%d %d", &a, &b) == 2){
int g = gcd(a, b);
a /= g; b /= g;
int det = a * a - 4 * b;
if(det < 0){ puts("No Solution"); continue; }
int t = int(sqrt(det+0.5));
int x1 = a - t;
if(t * t != det || x1 < 0 || x1 % 2){ puts("No Solution"); continue; }
int x2 = a + t;
printf("%d %d\n", x1*g/2, x2*g/2);
}
return 0;
}
HDU 5974 A Simple Math Problem (解方程)的更多相关文章
- hdu 5974 A Simple Math Problem
A Simple Math Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- HDU 5974 A Simple Math Problem 数学题
http://acm.hdu.edu.cn/showproblem.php?pid=5974 遇到数学题真的跪.. 题目要求 X + Y = a lcm(X, Y) = b 设c = gcd(x, y ...
- HDU - 5974 A Simple Math Problem (数论 GCD)
题目描述: Given two positive integers a and b,find suitable X and Y to meet the conditions: X+Y=a Least ...
- hdu 5974 A Simple Math Problem(数学题)
Problem Description Given two positive integers a and b,find suitable X and Y to meet the conditions ...
- HDU 5974 A Simple Math Problem(数论+结论)
Problem Description Given two positive integers a and b,find suitable X and Y to meet the conditions ...
- HDU 5974 A Simple Math Problem ——(数论,大连区域赛)
给大一的排位赛中数论的一题.好吧不会做...提供一个题解吧:http://blog.csdn.net/aozil_yang/article/details/53538854. 又学了一个新的公式..如 ...
- [数论] hdu 5974 A Simple Math Problem (数论gcd)
传送门 •题意 一直整数$a,b$,有 $\left\{\begin{matrix}x+y=a\\ LCM(x*y)=b \end{matrix}\right.$ 求$x,y$ •思路 解题重点:若$ ...
- hdu 5974 A Simple Math Problem gcd(x,y)=gcd((x+y),lcm(x,y))
题目链接 题意 现有\[x+y=a\\lcm(x,y)=b\]找出满足条件的正整数\(x,y\). \(a\leq 2e5,b\leq 1e9,数据组数12W\). 思路 结论 \(gcd(x,y)= ...
- HDU 5974"A Simple Math Problem"(GCD(a,b) = GCD(a+b,ab) = 1)
传送门 •题意 已知 $a,b$,求满足 $x+y=a\ ,\ LCM(x,y)=b$ 条件的 $x,y$: 其中,$a,b$ 为正整数,$x,y$ 为整数: •题解 关键式子:设 $a,b$ 为正整 ...
随机推荐
- location记录<18.7.21>
// var index = location.href; // console.log(index) // // indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置. // v ...
- Android系统篇之—-编写简单的驱动程序并且将其编译到内核源码中【转】
本文转载自:大神 通过之前的一篇文章,我们了解了 Android中的Binder机制和远程服务调用 在这篇文章中主要介绍了Android中的应用在调用一些系统服务的时候的原理,那么接下来就继续来介绍一 ...
- POJ 2536 之 Gopher II(二分图最大匹配)
Gopher II Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6675 Accepted: 2732 Descrip ...
- 二分 连续上升子序列变形 UVA1471
最大上升子序列解法: 1.动规转移方程 2.(nlogn) #include<cstdio> #include<algorithm> using namespace std; ...
- EntityFramework 学习 一 Entity Framework 查询设计
First/FirstOrDefault: using (var ctx = new SchoolDBEntities()) { var student = (from s in ctx.Studen ...
- C语言中的位操作(16)--计算二进制数字尾部连续0的数目
本篇文章介绍计算二进制数字尾部连续0的数目的相关算法,例如:v=(1101000)2,该数尾部连续0的数目=3 方法1:线性时间算法 unsigned int v; // 需要计算的目标整数 int ...
- HIVE- 大数据运维之hive管理
我现在在一家公司负责大数据平台(CDH平台)的运维管理,最常遇见的问题我总结出来,并且继续在下面更新.希望方便自己以后trouble shooting以及方便各位同行解决问题与学习. 关于做运维有几个 ...
- 使用jQuery为博客生成目录
这段代码展示了如何为div#content中的内容生成目录,也无非是对h系列标记进行解析.当然,也早有一些人实现了.1. [代码][HTML]代码 <html> <h ...
- linux命令学习笔记(17):whereis 命令
whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b).man说明文件(参数-m)和 源代码文件(参数-s).如果省略参数,则返回所有信息. 和find相比,whereis查找的速度 ...
- BZOJ3033 太鼓达人
3033: 太鼓达人 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 690 Solved: 497[Submit][Status][Discuss] ...