题意:求有多少对(a,b) 使lcm(a,b) = n。
思路:对n因子分解,暴力枚举。
代码:
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long LL;
LL n,top,a[10005];
LL gcd(LL a,LL b){
return b != 0 ? gcd(b,a%b) : a;
}
LL lcm(LL a,LL b){
return a * b / gcd(a,b);
}
int main(){
while(~scanf("%d",&n)){
if(n == 0) break;
top = 0;
for(int i = 1; i * i <= n ; i++){
if(n % i == 0){
a[top++] = i;
a[top++] = n / i;
}
}
if(a[top-1] == a[top-2]) top--;
LL ans = 0;
for(int i = 0 ;i < top ; i++){
for(int j = i; j < top ; j++)
if(lcm(a[i],a[j]) == n) ans++;
}
printf("%lld %lld\n",n,ans);
}
return 0;
}