[Prehistoric giant pitfall] Number Theory template integration and number theory template Integration

Source: Internet
Author: User

[Prehistoric giant pitfall] Number Theory template integration and number theory template Integration

This afternoon, Shen Yu told me a piece of number theory = I found that I couldn't play happily.
Sort out all the content templates.
This is a prehistoric giant pitfall, and the time is definitely not enough... Enter orz in the future

# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <algorithm> # define MAXN 1000000 using namespace std; bool not_prime [MAXN]; int prime_number [MAXN]; int nu; int factor [MAXN]; // record the minimum prime factor void prime () // line sieve {for (int I = 2; I <= MAXN; I ++) {if (! Not_prime [I]) {prime_number [++ nu] = I; factor [I] = I;} for (int j = 1; j <= nu & I * prime_number [j] <= MAXN; j ++) {not_prime [I * prime_number [j] = 1; f [I * prime_number [j] = prime_number [j]; if (I % prime_number [j] = 0) break ;}}} int mu [MAXN] = {0, 1}; void mu () // Mobius function {for (int I = 2; I <= MAXN; I ++) {if (! Not_prime [I]) mu [I] =-1; for (int j = 1; j <= nu & I * prime_number [j] <= MAXN; j ++) {not_prime [I * prime_number [j] = 1; if (I % prime_number [j] = 0) {mu [I * prime_number [j] = 0; break;} else {mu [I * prime_number [j] =-mu [I] ;}}} int phi [MAXN]; void phi () // Euler's function {for (int I = 2; I <= MAXN; I ++) {if (! Not_prime [I]) {phi [I] = I-1;} for (int j = 1; j <= nu & I * prime_number [j] <= MAXN; j ++) {not_prime [I * prime_number [j] = 1; if (I % prime_number [j] = 0) {phi [I * prime_number [j] = phi [I] * prime_number [j]; break ;} else {phi [I * prime_number [j] = phi [I] * (prime_number [j]-1) ;}}} int inv [MAXN]; // The following continuous reverse element void inv1 () // Fermat Theorem {for (int I = 1; I <= MAXN; I ++) inv [I] = pow (I, phi [p]-1) % p; // p is determined based on the subject requirements} void inv2 () // Method Based on line sieve {for (in T I = 2; I <= MAXN; I ++) {int a = p/I; int B = p % I; inv [I] = (p-) * inv [B] % p ;}} void inv3 () // factorial-Based Query {unsigned long a [MAXN] = {1}, rev [MAXN]; // This factorial is slightly larger than 0-0. I don't want to write high precision. unsigned, let's look at it. for (int I = 1; I <= MAXN; I ++) a [I] = a [I-1] * I; rev [MAXN] = pow (a [MAXN], phi [p]-1) % p; for (int I = MAXN-1; I> = 0; I --) rev [I] = rev [I + 1] * (I + 1) % p; for (int I = 1; I <= MAXN; I ++) inv [I] = a [I-1] * rev [I];} void inv4 () // The method based on a * I + B = p. This method is only used when p is a prime number {inv [1] = 1; for (int I = 2; I <= MAXN; I ++) {int a = p/I; int B = p % I; inv [I] = (p-) * inv [B] % p ;}// returns the Chinese Remainder theorem, which contains the original root, discrete logarithm, and Lucas theorem. the mobius Inversion is not complete =. = // Thank you for your teaching. He talked about the last three methods in the reverse element and the Mobius function... /* Int main (){}*/

It should be correct. QUQ. If there is any sand tea error, please tell me immediately that I am such a sand tea after all.

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.