Lightoj 1054-efficient Pseudo Code

Source: Internet
Author: User

Topic Connection:

http://www.lightoj.com/volume_showproblem.php?problem=1054

Main topic:

Given n,m, what is the sum of all the factors that ask n^m?

Problem Solving Ideas:

Additional knowledge:

1: For a digital n=p1^t1+p2^t2+p3^t3+.........+pn^tn. The sum of the added sum of the n factor and the corresponding value equivalent to the subset of n All factors-(P1^0+P1^1+P1^2+......+P1^T1) * (P2^0+P2^1+......+P2^T2) *.....* (PN^0+PN^1+......+PN^TN) .

2: Geometric series summation formula:

3: Division Take-Over: (A/b)%p = = a% (b%p)/b%p;

a/b%p = = a*b^ (p-2)%p; (when P is prime) proof: There is a Fermat theorem: P is a prime number, (b,p) = 1, b^ (p-1)%p = = 1,a/b%p = a/b*1%p = a/b*b^ (p-1)% = a*b^ (p-2)%p.

1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intMoD =1000000007;5 Const intMAXN =7000;6typedefLong LongLL;7 intISPRIME[MAXN], prime[maxn*Ten];8 LL sum, K;9 Ten voidIsPrime () One{//filter out the number of prime numbers needed A     intI, J; -      for(i=2, k=0; i<70000; i++) -         if(!Prime[i]) the         { -Isprime[k + +] =i; -              for(J=i; j<70000; j+=i) -PRIME[J] =1; +         } -        //printf ("%d\n", k); + } A  at ll Pow (ll X, ll y) -{//Fast Power seeking x^y -LL num =1; -      while(y) -     { -         if(Y%2) innum = (num * x)%MoD; -x = (x * x)%MoD; toY/=2; +     } -     returnnum; the } * ll solve (ll X, ll y) $ {Panax Notoginseng LL num; -num = (Pow (x, y)-1); thenum = (num * POW (x1, mod-2)) %MoD; +     return(num + MoD)%MoD; A } the  + intMain () - { $LL t, N, m, L =0; $ IsPrime (); -scanf ("%lld", &t); -      while(T--) the     { -scanf ("%lld%lld", &n, &m);Wuyi LL A, B, I; thei =0; -sum =1; Wu          while(I <k) -         { About             if(1==N) $                  Break; -A = b =0;//count the number of prime factors and factors -             if(n% isprime[i] = =0) -             { AA =Isprime[i]; +                  while(n% isprime[i] = =0) the                     { -B + +; $N/=Isprime[i]; the                     } thesum = (sum * Solve (A, b*m+1) ) %MoD; the             } thei + +; -              in         } the         if(n! =1) thesum = (sum * Solve (n, m+1)) %MoD; Aboutprintf ("Case %lld:%lld\n", ++l, sum); the     } the     return 0; the}

Lightoj 1054-efficient Pseudo Code

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.