Thoughts on learning Euler's Phi Functions

Source: Internet
Author: User

The correctness thinking is written on the Code chip.


Forget one thing: the role of the Euler Phi function is to evaluate 1 ~ Number of units in N

# Include <cstdio> # include <cstring> # include <cmath> int Phi [5000000]; // If the calculated number is 6, when I = 2 and I = 3, it will enter the inner loop. // once it enters the inner loop, it will calculate the Euler's formula based on the prime number. // insert: euler's formula: Phi (n) = N * (1-1/P1) * (1-1/P2 )*... (1-1/PN) // you can think that for each definite number N, the Euler's formula is not completed in a loop, /// but it can be proved that when the entire cycle is completed, the Euler's formula is completed. In other words, it can ensure that) in this array, the correct answer is calculated strictly according to the Euler's formula, instead of following other algorithms void phi_table (int n, int * PHI) {for (INT I = 2; I <= N; I ++) {Phi [I] = 0;} Phi [1] = 1; for (INT I = 2; I <= N; I ++) {If (! Phi [I]) {for (Int J = I; j <= N; j + = I) {If (! Phi [J]) Phi [J] = J; Phi [J] = Phi [J]/I * (I-1) ;}}} int main () {phi_table (10000, Phi); int N; while (scanf ("% d", & N) printf ("% d \ n", Phi [N]);}

The code for printing the Euler's function value in the above Code is correct, but the whole code is to verify and prove the Euler's Phi function, there is no other intention

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.