LightOJ 1236 Pairs Forming LCM
题意:
long long pairsFormLCM( int n ) {
long long res = 0;
for( int i = 1; i <= n; i++ )
for( int j = i; j <= n; j++ )
if( lcm(i, j) == n ) res++; // lcm means least common multiple
return res;
}
在n<=10^14的情况下实现上述代码。
思路:
前些天还写过一题算术基本定理的题解,现在发现理解还不够透彻,比如这题按理来说应该是算术基本定理的模板题,但我居然没看出来。。
求约数,倍数,质因数,gcd,lcm,都应该想到这个定理的。
算术基本定理的内涵用一句话来概括就是:
一个数的每一个质因子的不同幂对应不同的因数。
而这题,我们假设( a , b ) = n ,那么:
n=pk11pk22⋯pkss,a=pd11pd22⋯pdss, b=pe1