题目链接

大意:给你两个数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. SpringCloud-Gateway

    在微服务架构中,我们会遇到这样的问题:1.在调用微服务时,需要鉴权,微服务不能任意给外部调用.但是,多个微服务如果都需要同一套鉴权规则,明显会产生冗余,如果鉴权方法需要修改,则需要改动多个地方.2.在 ...

  2. MacOS 10.13.6 下装xcode 流程

    1.最好先安装brew https://github.com/Homebrew/brew/releases 自动安装脚本 /usr/bin/ruby -e "$(curl -fsSL htt ...

  3. resnet18全连接层改成卷积层

    想要尝试一下将resnet18最后一层的全连接层改成卷积层看会不会对网络效果和网络大小有什么影响 1.首先先对train.py中的更改是: train.py代码可见:pytorch实现性别检测 # m ...

  4. ios之库Protobuf的使用

    https://blog.csdn.net/dangbai01_/article/details/81099001 (1)Protobuf是什么? Protobuf 即 google protocol ...

  5. webpack(一) 配置

    一.entry  & output mode: 'development', // entry: './src/index', // entry: ['./src/index', './src ...

  6. git submoudle提交

    进入到各个submoudle文件夹 git status 查看所在branch和文件修改状态 git add [files]; git commit "" git pull ori ...

  7. Django3 Django 路由分发,反向解析,2.0版本的path

    urls配置像Django 所支撑网站的目录.它的本质是URL与要为该URL调用的视图函数之间的映射表:你就是以这种方式告诉Django,对于客户端发来的某个URL调用哪一段逻辑代码对应执行. 1.简 ...

  8. 关于Oracle使用管理员账号登录失败的问题

    我在本地建的Oracle数据库在调试自己写的存储过程的时候提示缺少 debug connect session 权限,一般情况下根据这个提示直接用管理员账号登录进去,执行 grant debug co ...

  9. Android数据库优化

    1.索引 简单的说,索引就像书本的目录,目录可以快速找到所在页数,数据库中索引可以帮助快速找到数据,而不用全表扫描,合适的索引可以大大提高数据库查询的效率.(1). 优点大大加快了数据库检索的速度,包 ...

  10. Oracle查询所有表的字段明细

    SELECT USER_TAB_COLS.TABLE_NAME as 表名, UTC.COMMENTS as 表中文名, USER_TAB_COLS.COLUMN_ID as 列序号, USER_TA ...