求有多少组 a<=b ,lcm(a,b)==n
分解因子,暴力求。
Problem F
LCM Cardinality
Input: Standard Input
Output: Standard Output
Time Limit: 2 Seconds
A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible pairs. For example 12 is the LCM of (1, 12), (2, 12), (3,4) etc. For a given positive integer N, the number of different integer pairs with LCM is equal to N can be called the LCMcardinality of that number N. In this problem your job is to find out the LCM cardinality of a number.
Input
The input file contains at most 101 lines of inputs. Each line contains an integer N (0<N<=2*109). Input is terminated by a line containing a single zero. This line should not be processed.
Output
For each line of input except the last one produce one line of output. This line contains two integers N and C. Here N is the input number and Cis its cardinality. These two numbers are separated by a single space.
Sample Input Output for Sample Input
2 12 24 101101291 0 |
2 2 12 8 24 11 101101291 5 |
Problem setter: Shahriar Manzoor
Special Thanks: Derek Kisman
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long LL;
LL gcd(LL a,LL b)
{
return b==0?a:gcd(b,a%b);
}
LL lcm(LL a,LL b)
{
return a/gcd(a,b)*b;
}
int n,fac[9999999],top;
LL ans;
int main()
{
while(~scanf("%d",&n)&&n)
{
int tmp=sqrt(n+0.5);
top=ans=0;
for(int i=1;i<=tmp;i++)
{
if(n%i==0)
{
fac[top++]=i;
fac[top++]=n/i;
}
}
if(fac[top-1]==fac[top-2]) top--;
for(int i=0;i<top;i++)
for(int j=i;j<top;j++)
if(lcm(fac[i],fac[j])==n) ans++;
printf("%d %lld\n",n,ans);
}
return 0;
}
本文探讨了对于给定正整数N,有多少组不同的整数对(a, b),使得a≤b且它们的最小公倍数等于N的问题。通过分解因数的方法,采用暴力搜索策略来找出所有符合条件的整数对。

1288

被折叠的 条评论
为什么被折叠?



