Hdu2824 Euler's formula-tabulation Algorithm

Source: Internet
Author: User

 

HDU 2824 the Euler function
Euler's function: θ (n) is the number of Integers of All integers less than N, and N. N is a positive integer.
Euler proves the following formula:
If the standard prime factor decomposition formula of N is P1 ^ A1 * P2 ^ A2 *...... * PM ^ am, where all PJ (j = ,......, M) are all prime numbers, and they are not equal to each other. Then there is
Phi (n) = N (1-1/P1) (1-1/P2 )...... (1-1/pm)
If n is an odd prime number, Phi (n) = n-1.
Solution: Linear Regression Method
In Program Using the following Euler's function, you can quickly find the Euler's value (A is a qualitative factor of N)
(1) If (N % A = 0 & (n/a) % A = 0), E (n) = E (N/) *;

(2) If (N % A = 0 & (n/a) %! = 0) then there are: E (n) = E (n/a) * (A-1 );

 
# Include <stdio. h> # include <stdlib. h >__ int64 num [3000024]; int prime [220000]; bool isprime [3000024] = {0}; void Eular () {int COUNT = 0 ;__ int64 K; for (INT I = 2; I <= 3000000; I ++) {If (! Isprime [I]) {Prime [++ count] = I; num [I] = I-1;} For (Int J = 1; j <= count & (k = prime [J] * I) <= 3000000); j ++) {isprime [k] = 1; if (I % prime [J] = 0) {num [k] = num [I] * prime [J];} else num [k] = num [I] * (Prime [J]-1) ;}} int main () {int n, m, I; Eular (); // The results are stored in num [] for (I = 3; I <= 3000000; I ++) num [I] = num [I-1] + num [I]; while (scanf ("% d", & N, & M )! = EOF) printf ("% i64d \ n", num [m]-num [n-1]); Return 0 ;}

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.