题目链接

大意:给你两个数X,YX,YX,Y,让你找两个数a,ba,ba,b,满足a+b=X,lcm(a,b)=Ya+b=X,lcm(a,b)=Ya+b=X,lcm(a,b)=Y.

思路:枚举gcd(a,b)gcd(a,b)gcd(a,b),假设gcd(a,b)=k,那么a=xa∗k,b=xb∗k,gcd(a,b)=k,那么a=x_a*k,b=x_b*k,gcd(a,b)=k,那么a=xa​∗k,b=xb​∗k,化简上面给的两个式子即可得到

xa+xb=Xk,xa∗xb=Ykx_a+x_b=\frac{X}{k},x_a*x_b=\frac{Y}{k}xa​+xb​=kX​,xa​∗xb​=kY​,显然这是一个方程组,将xb=Xk−xax_b=\frac{X}{k}-x_axb​=kX​−xa​代入第二个式子即可得到一个一元二次方程,解这个方程即可。

#include<bits/stdc++.h>

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back using namespace std; LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
int a,b;
int main(){
ios::sync_with_stdio(false);
while(cin>>a>>b){
int q=sqrt(a);
int sta=0,anL,anR;
for(int i=1;i<=q;i++){
if(a%i)continue;
int A=a/i;
int B=b/i;
if(A*A<4*B)continue;
int T=floor(sqrt(A*A-4*B));
if(T*T!=A*A-4*B)continue;
else {
if((A-T)%2||(A+T)%2)continue;
int L=(A-T)/2*i;
int R=(A+T)/2*i;
if(lcm(L,R)!=b)continue;
anL=(A-T)/2*i;
anR=(A+T)/2*i;
sta=1;
break;
}
}
for(int i=1;i<=q&&!sta;i++){
if(a%i)continue;
int A=a/(a/i);
int B=b/(a/i);
if(A*A<4*B)continue;
int T=floor(sqrt(A*A-4*B));
if(T*T!=A*A-4*B){continue;}
else {
if((A-T)%2||(A+T)%2){continue;}
int L=(A-T)/2*(a/i);
int R=(A+T)/2*(a/i);
if(lcm(L,R)!=b){continue;}
anL=(A-T)/2*(a/i);
anR=(A+T)/2*(a/i);
sta=1;
break;
}
}
if(!sta)cout<<"No Solution\n";
else cout<<anL<<' '<<anR<<endl;
}
return 0;
}

hdu5974 A Simple Math Problem(数学)的更多相关文章

  1. FZYZ-2071 A Simple Math Problem IX

    P2071 -- A Simple Math Problem IX 时间限制:1000MS      内存限制:262144KB 状态:Accepted      标签:    数学问题-博弈论    ...

  2. hdu 1757 A Simple Math Problem (乘法矩阵)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  3. HDU1757 A Simple Math Problem 矩阵快速幂

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  4. hdu------(1757)A Simple Math Problem(简单矩阵快速幂)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. A Simple Math Problem(矩阵快速幂)(寒假闭关第一题,有点曲折啊)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...

  6. HDU 1757 A Simple Math Problem (矩阵快速幂)

    题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...

  7. HDU 1757 A Simple Math Problem(矩阵)

    A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...

  8. HDU 1757 A Simple Math Problem (矩阵乘法)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. hdu 5974 A Simple Math Problem

    A Simple Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

随机推荐

  1. git tag 打标签

    注意:在哪个分支上打tag一定要先提交该分支到远程gitlab仓库 标签(tag)操作 1. 查看所有标签 git tag 默认标签是打在最新提交的commit上的 2.本地打新标签 git tag ...

  2. 【html】使用img标签和背景图片之间的区别

    1.加载问题 背景图片会等到html结构加载完成才开始加载 img标签是网页结构的一部分,会在html结构加载的时候加载 在网页加载的过程中,背景图片会等到结构加载完成(网页的内容全部显示以后)才开始 ...

  3. 好程序员告诉你HTML好在哪里,为什么值得我们学习

    好程序员告诉你HTML好在哪里,为什么值得我们学习,HTML5对于用户来说,提高了用户体验,加强了视觉感受.HTML5技术在移动端,能够让应用程序回归到网页,并对网页的功能进行扩展,用户不需要下载客户 ...

  4. [LeetCode] 19. 删除链表的倒数第N个节点

    题目链接:https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/ 题目描述: 给定一个链表,删除链表的倒数第 n 个节点, ...

  5. vue 追书神器

    app.vue页面 初始化数据,通过调用vuex mutation里定义的方法 调用保存到localstorage中的书架信息.搜索历史记录.字体大小和皮肤 并把这些数据保存的vuex state中 ...

  6. zoj 3605

    链接 [https://vjudge.net/contest/293343#problem/F] 题意 就是有n碗,有一个宝石,知道开始宝石在那个碗下面 进行M次交换,但知道其中的k次,问你最可能在那 ...

  7. Jmeter二次开发代码(2)

    /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreem ...

  8. js 时间格式,加减

    Date.prototype.Format = function (fmt) { //author: rixiao var o = { "M+": this.getMonth() ...

  9. nginx--default_server定义规则及配置

    nginx 的 default_server 指令可以定义默认的 server 出处理一些没有成功匹配 server_name 的请求,如果没有显式定义,则会选取第一个定义的 server 作为 de ...

  10. x86/x64/x86_64/i386/ia32/ia64/amd/amd64 辨析

    x64 = x86_64 = amd64 64位指令集,是对IA-32的扩展,由AMD提出,implemented by AMD,Intel.可兼容32位指令集(IA-32) 目前大部分64位计算机均 ...