Title Link: http://lightoj.com/volume_showproblem.php?problem=1341
Test instructions: Give two number A, B, satisfy c * d = A and c>=b and D>=b C, d two-tuple logarithm, (c, D) and (d, c) belong to the same situation.
Idea: According to the unique decomposition theorem, a unique decomposition of a, then the number of all positive numbers of a is num = (1 + A1) * (1 + a2) *...* (1 + AI), where the AI is the index of the element factor. Now we know that the number of factors in a is num, assuming that the factor is from small to large columns
X1,X2,..., Xnum because it is for the two-tuple, num is divided by 2, then minus those smaller than B (smaller than b a certain and relatively large combination, so do not consider a large case).
Code
1#include <cstdio>2#include <cstring>3 using namespacestd;4 5typedefLong LongLL;6 Const intMAXN =1000000;7 8 intPRIME[MAXN +1];9 Ten voidgetprime () One { Amemset (Prime,0,sizeof(prime)); - for(inti =2; I <= MAXN; ++i) { - if(!prime[i]) prime[++prime[0]] =i; the for(intj =1; J <= prime[0] && Prime[j] <= maxn/i; ++j) { -PRIME[PRIME[J] * I] =1; - if(i% prime[j] = =0) Break; - } + } - } + ALL factor[ +][2]; at intfatcnt; - - intgetfactors (LL x) - { -fatcnt =0; -LL tmp =x; in for(inti =1; I <= prime[0] && prime[i] * prime[i] <= tmp; ++i) { -factor[fatcnt][1] =0; to if(tmp% prime[i] = =0) { +factor[fatcnt][0] =Prime[i]; - while(tmp% prime[i] = =0) { the++factor[fatcnt][1]; *TMP/=Prime[i]; $ }Panax Notoginseng++fatcnt; - } the } + if(TMP! =1) { Afactor[fatcnt][0] =tmp; thefactor[fatcnt++][1] =1; + } -LL ret =1; $ for(inti =0; i < fatcnt; ++i) { $RET *= (1L+ factor[i][1]); - } - returnret; the } - Wuyi intMain () the { - getprime (); Wu intncase; -scanf"%d", &ncase); About for(intCNT =1; CNT <= ncase; ++CNT) { $ LL A, b; -scanf"%lld%lld", &a, &b); - if(b * b >a) { -printf"Case %d:0\n", CNT); A Continue; + } theLL num =Getfactors (a); -Num/=2; $ for(inti =1; I < b; ++i) { the if(a% i = =0) --num; the } theprintf"Case %d:%lld\n", CNT, num); the } - return 0; in}
Loj 1341 Aladdin and the Flying Carpet (mass factor decomposition)