[POJ1845] Sumdiv

Source: Internet
Author: User

This problem examines the formula theorems of three number theory:

Integer unique decomposition theorem: a= (P1^K1) * (P2^K2) **...* (PN^KN) (P (i) is prime)

factors and formulas (known as a= (P1^K1) * (P2^K2) **...* (PN^KN)), then the sum of all the factors of a is: sums = (1+P1+P1^2+...P1^K1) * (1+P2+P2^2+...P2^K2) *...* (1+PN+PN^2+...PN^KN)

The same comodule formula:

(a+b)%m= (a%m+b%m)%m

(a*b)%m= (a%m*b%m)%m

The code is as follows:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <vector>5#include <algorithm>6#include <cmath>7 8 using namespacestd;9 TentypedefLong LongLL; One Const intMoD =9901; AVector<ll>p; -Vector<ll>K; - LL N, a, B; the  - //Fast Power - ll Quickmul (ll X, ll N) { -LL ans =1; +LL T =x; -      while(n) { +         if(N &1) { AAns = (ans * t)%MoD; at         } -t = t%MoD; -N >>=1; -     } -     returnans; - } in  - //Decomposition factorization to voidfactor (LL N) { + p.clear (); - k.clear (); the     intnn = (int) sqrt (n1.0); *      for(inti =2; I <= nn; i+=2) { $         if(n% i = =0) {//decompose N to turn N into p1^k1*p2^k2+...pn^knPanax Notoginseng P.push_back (i); -K.push_back (0); the              while(n% i = =0) { +K.back () + +; An = n/i; the             } +         } -         if(i = =2) { $i--; $         } -         if(n = =1){ -              Break; the         } -     }Wuyi     if(n! =1) {//Special Prime number the p.push_back (n); -K.push_back (1); Wu     } - } About  $ //The same comodule formula - //(a+b)%m= (a%m+b%m)%m - //(a*b)%m= (a%m*b%m)%m - //the 1+pi+pi^2+...+pi^n and the two-part seeking A ll Modu (ll X,ll y) { +     if(Y = =0) { the         return 1;  -     } $     if(Y%2==0) { the         return((Modu (x,y/2-1) * ((%mod) * (1+quickmul (x,y/2+1)) (%mod))%mod+quickmul (x,y/2)%mod)%MoD;  the     } the     if(Y%2!=0) { the         return(Modu (x,y/2) * ((%mod) * (1+quickmul (x,y/2+1))%mod)%MoD;  -     } in } the  the voidsolve () { AboutFactor (a);//decompose A to make a = P1^k1*p2^k2+...pn^kn the      for(inti =0; I < k.size (); i++) { theK[i] = k[i] * b;//so a^b = p1^ (k1*b) *p2^ (k2*b) ... pn^ (kn*b) the     } +LL sum =1; -      for(inti =0; I < k.size (); i++) { thesum = sum * MODU (P[i], k[i])%MoD;Bayi     } theprintf"%i64d\n", sum); the } -  - intMain () { the      while(~SCANF ("%d%d", &a, &b)) { the solve (); the     } the     return 0; -}

[POJ1845] Sumdiv

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.