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

根据题意,数对交换位置算不同数对,所以只要考虑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 @ 2025-02-10 20:32  十柒*  阅读(22)  评论(0)    收藏  举报