HDU 1452 Happy 2004 (Factor and integrable function)

Source: Internet
Author: User

Topic links

Test instructions: Give you an X that allows you to find the sum of all the factors of X 2004, and then take the remainder to 29.

Idea: Originally this is the integrable function, point here here, here is very detailed.

In the field of non-number theory, the integrable function refers to all functions that have the Properties F (AB) =f (a) f (b) for any and b .

The integrable function in number theory: for an arithmetic function f (n)of a positive integer n , if f ( 1) =1, and when a, b coprime f (AB) =f (a) f (b), In number theory, it is called the integrable function.

If for an integrable function f (n), even if A, b is not coprime, there is also F (AB) =f (a) f (b), it is said to be fully integrable.

S (6) =s (2) *s (3) =3*4=12;

S (=s) (4) *s (5) =7*6=42;

Look at s () = 1+2+5+10+25+50=93=3*31=s (2) *s (+), s (+) =1+5+25=31.

This is called the integrable function in number theory, when gcd (A, b) =1 s (a*b) =s (a) *s (b);

If P is prime: S (p^n) =1+p+p^2+...+p^n= (p^ (n+1)-1)/(P-1)-----is actually the geometric series summation formula (1)

Look at the subject again:

Calculation factor and s (2004^x) mod,

2004=2^2 *167

2004^x=4^x * 3^x *167^x

s (2004^x)) = (s (2^2x) )) * (S (3^x))) * (S (167^x))) and 167%29=22

S (2004^x)) = (s (2^2x))) * (S (3^x))) * (S (22^x)))

a=s (2^2x) = (2^ (2x+1)-1)// according to (1)

b=s (3^x) = (3^ (x+1)-1)/2// according to (1)

c=s (22^x) = (22^ (x+1)-1)/21// according to (1)

% algorithm

1. (a*b)%p= (a%p) * (b%p) multiplication

2. (A/b)%p= (a *b^ ( -1)%p) Division

s (2004^x) =(2^ (2x+1)-1)* (3^ (x+1)-1)/2 * (22^ (x+1)-1)/21

(a*b)//%m= a%m* b%m * INV (c)

C*INV (c) =1%M modulus is 1 of all the number inv(C) is the smallest can be divisible by C

INV (2) =15, INV (+) =18 2*15=1 mod, 18*21=1 mod 29

s (2004^x) =((2^ (2x+1)-1)* (3^ (x+1)-1)/2 * (22^ (x+1)-1)/21)mod = ((2^ ( 2x+1)-1) * (3^ (x+1)-1) *15 * (22^ (x+1)-1) *18) mod29

b^ ( -1) is the inverse element of b (%p), which is the inv above

The inverse element of 2 is the 2*15=30% 29=1%

The inverse of the element is, because 21*18=378% =1%

So

a=(powi (2,2*x+1,29)-1)%;

B= (Powi (3,x+1,29)-1) *15% 29;

C= (Powi (22,x+1,29)-1) *18% 29;

ans=(a*b)% 29*c%;

1 //14522#include <stdio.h>3#include <math.h>4#include <iostream>5 6 using namespacestd;7 8 intMultimod (intAintN//The exponentiation mode9 {Ten     intres =1 ; One      while(n) A     { -         if(N &1) -         { theRes *=A; -Res%= in ; -         } -A *=A; +A%= in ; -N >>=1 ; +     } A     returnRes; at } - intMain () - { -     intx; -      while(~SCANF ("%d",&x)) -     { in         if(x = =0) Break ; -         intA = (Multimod (2,2*x+1)-1) ; to         intb = (Multimod (3, x+1)-1)* the ; +         intc = (Multimod (167, x+1)-1)* - ; -printf"%d\n", (a*b*c)% in) ; the     } *     return 0 ; $}
View 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.