最大公约数和最小公倍数问题

根据题意,数对交换位置算不同数对,所以只要考虑p<=q就行了,交换一下就是结果乘二,但要注意当p=q时要减掉一。最小公倍数可以用pq==xy来代替,最大公约数就是gcd(p,q);
`#include<stdio.h>

include

include

include<stdlib.h>

include<string.h>

include

include<math.h>

include<bits/stdc++.h>

using namespace std;

int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
}

int min_(int a,int b){
return a*b/gcd(a,b);
}

int main(){
int sum=0,x,y;
scanf("%d %d",&x,&y);
if(xy) sum--;
if(x>y){
printf("%d",sum);
}
else{
for(int i=1;i<=sqrt(xy);i++){
if(x
y%i
0&&gcd(i,x*y/i)==x){
sum+=2;
}
}
printf("%d",sum);
}
return 0;
} `

posted @   十柒*  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示