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

题目地址


#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
int main(){
	int x,y;
	scanf("%d%d",&x,&y);
	int ans=0;
	for(int p=2;p<=sqrt(x*y);p++){
		if(!(x*y%p)){//条件1 
			if(gcd(p,(x*y)/p)==x){
				ans++;
			}
		}
	}
	printf("%d
",ans*2);
	return 0;
}
原文地址:https://www.cnblogs.com/zbsy-wwx/p/11680522.html