Loj 1341 Aladdin and the Flying Carpet (mass factor decomposition)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.