Find the result of the following code: 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 r…
题解:这道题要从n的角度来考虑i和j. n可以表示为n=a1^p1*a2^p2*a3^p3.......n=lcm(i,j),那么质因子a1^p1,a1可以在i或者j中,并且p1=max(a1i,a1j)即pi为i中ai和j中ai的最大值.假设a1在i中,对于质因子a1,b中有[0,p1],一共有p1+1中选择. a1在j中同理,a也有p1+1中选择.所以一共有2(p1+1)-1种情况.为什么要减去1呢?如果i中有p1个a1,b中也有p1个a1,这种情况我们算了两次.所以要减去1.然后累乘.这样…
题意: 就是求1-n中有多少对i 和 j 的最小公倍数为n  (i <= j) 解析: 而这题,我们假设( a , b ) = n ,那么: n=pk11pk22⋯pkss, a=pd11pd22⋯pdss, b=pe11pe22⋯pess, 可以确定max(ei,di)=ki,      关于这点 可以自己反证一下 那么ki的组成就是ei与di中一个等于ki, 另一个任取[0,ki-1]中的一个数, 那么就有 2ki 种方案, 由于 ei=di=ki 只有一种,(两种都为ki) 所以第i位方案…
Aladdin and the Flying Carpet (LightOJ - 1341)[简单数论][算术基本定理][分解质因数](未完成) 标签:入门讲座题解 数论 题目描述 It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first myste…
Sigma Function (LightOJ - 1336)[简单数论][算术基本定理][思维] 标签: 入门讲座题解 数论 题目描述 Sigma function is an interesting function in Number Theory. It is denoted by the Greek letter Sigma (σ). This function actually denotes the sum of all divisors of a number. For exam…
Pairs Forming LCM (LightOJ - 1236)[简单数论][质因数分解][算术基本定理](未完成) 标签: 入门讲座题解 数论 题目描述 Find the result of the following code: 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) ==…
http://lightoj.com/volume_showproblem.php?problem=1236 Pairs Forming LCM Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1236 Description Find the result of the following code: long long pairs…
B - Pairs Forming LCM Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1236 Description Find the result of the following code: long long pairsFormLCM( int n ) {    long long res = 0;    for( in…
1236 - Pairs Forming LCM   Find the result of the following code: 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…
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=109329#problem/B    全题在文末. 题意:在a,b中(a,b<=n)(1 ≤ n ≤ 1014),有多少组(a,b)  (a<b)满足lcm(a,b)==n; 先来看个知识点: 素因子分解:n = p1 ^ e1 * p2 ^ e2 *..........*pn ^ en for i in range(1,n): ei 从0取到ei的所有组合 必能包含所有n的因子. 现…