【洛谷】P1029 - 最大公约数和最小公倍数问题
2020-11-19 本文已影响0人
莫wen
public class Main{
static int max ;
static int min ;
static int JI ;
static int ans;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
max = sc.nextInt();
min = sc.nextInt();
JI = max * min;
int halfJI = (int) Math.sqrt(JI);
for (int i = 1; i <= halfJI; i++) {
if (JI%i == 0 && gcd(i,JI/i) == max) {
ans++;
}
}
if (max == min) {
System.out.println(ans);
}else {
System.out.println(ans*2);
}
}
private static int gcd(int x, int y) {
if (y == 0) return x ;
else return gcd(y,x%y);
}
}