Three important questions about number theory in algorithm competition
Prime arithmetic
Solving indefinite equations and the same Yu Fangcheng
Application of the integrable function
1. Example of prime number arithmetic experiment
1). Calculate all primes in [2,n] Interval
2) Large integer prime
The main idea: to give a number n, find out that you are all 1 of the smallest decimal number, so that n can divide this number. Only the minimum number of digits is output.Problem Analysis: Sheer number theory, violence.The code
FibonacciTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)Total submission (s): 3654 Accepted Submission (s): 1671Problem Description2007 year has come. After 2006 years of cultivation, mathematical prodigy Zouyu finally put 0 to 100000000 of Fibonacci seriesThe values (f[0]=0,f[1]=1;f[i] = f[i-1]+f[i-2] (i>=2) are all backed down.Next, Codestar decided to test him, so each asked him a number, he will say the answer, but
Different digits
Time Limit: 10000/4000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 382 accepted submission (s): 90 problem descriptiongiven a positive integer N, your task is to find a positive integer m, which is a multiple of N, and that M contains the least number of different digits when represented in decimal. for example, number 1334 contains three different
Digi
Euler's function:
Euler's function is a very important function in number theory. Euler's function refers to the number of positive integers (including 1) with a positive integer N, less than N and interlace with N, it is recorded as PHI (n ).
Complete remainder set:Defines a set of numbers less than N and with N mutual quality as Zn, and calls this set a comple
modulo p.
Sample Input
21 2 52 1 5
Sample output
33HintHintFor sample 1, squirrels will put no more than 2 beans in one tree. Since trees are different, we can label them as 1, 2 … and so on. The 3 ways are: put no beans, put 1 bean in tree 1 and put 2 beans in tree 1. For sample 2, the 3 ways are: put no beans, put 1 bean in tree 1 and put 1 bean in tree 2.
Source2009 multi-university training contest 13-hostBy hit
Recommendgaojie
A very powerful number
GCDTime limit:6000/3000 MS (java/others) Memory limit:32768/32768 K (java/others)Total submission (s): 5454 Accepted Submission (s): 1957Problem Descriptiongiven 5 integers:a, B, C, D, K, you ' re-find x in a...b, y in c...d that GCD (x, y) = K. GCD (x, y) Me Ans The greatest common divisor of x and Y. Since the number of choices may is very large, you ' re only required to output the total number of diff
equivalent toGCD (A-B) > 1 equivalent toGCD (2 * A, A + b) > 1Because A+b is odd.Equivalent toGCD (A, a +b) > 1 is equivalent toGCD (A, B) > 1Deduction EndThe following is a decomposition of the factorization, find the n number of different parity and meet gcd (A, B) > 1 numberThe number of the last plus parity is the answer.Therefore, the number of 1~MAXN and A
Theory:
Make H (1) = 1, h (0) = 1, and the catalan number meets the recursive formula:
H (n) = H (0) * H (n-1) + H (1) * H (n-2) +... + H (n-1) H (0) (N> = 2)Alternative recursion:H (n) = (4 * N-2)/(n + 1) * H (n-1 );The recursive relationship is resolved as follows:H (n) = C (2n, N)/(n + 1) (n = 1, 2, 3 ,...)
The application is as follows: 1. Brackets
Matrix chain multiplication: P = A1 × a2 ×
template. "TAT" number theory abuse me like a vegetable worm, even vegetable chicken can not forget ... AC Template ... /*/#include "map" #include "Cmath" #include "string" #include "Cstdio" #include "vector" #include "CString" #include "iostream "#include" algorithm "using namespace std;typedef long LL; ll EXGCD (ll a,ll b,ll x,ll y) {//Direct reference to save X and y in the entire process (N-M) x+ly=x-y
Tags: Mathematical Number Theory
7001. Visible lattice pointsproblem code: vlattice
Consider a n * n lattice. one corner is at (0, 0) and the opposite one is at (N, N, N ). how many lattice points are visible from corner at (0, 0 )? A point X is visible from point y IFF no other lattice point lies on the segment joining X and Y.Input:The first line contains the
; M = M' * k => X = K' * m + A = K' * K * m' + K * a' = K * (K' * m' + '); therefore, gcd (x, m) = k> 1. Likewise, if gcd (B, n)> 1, then gcd (x, n)> 1. Therefore, it is necessary for a and M * n to communicate with each other and B and N to communicate with each other.3) Next we will prove the adequacy: from X % m = A, we can get x = K * m + A; from the Euclidean algorithm, we can find the process of maximizing the common number (no proof, huh, huh,
prime[j] multiplied by whether I can be divisible prime[j], if possible, prove I*prime[j] has a prime[j] this factor, if not, then the number of its quality factor will be on the basis of the number of the I of the qualitative factor + 1Code#include using namespacestd;#defineN 1000100#defineMX 1000010#definell Long Longll T,n,cnt,c,k,mm;ll S[n],f[n],v[n],num[n],prime[n];voidPrimesintN) {num[1]=1; for(intI
gold plates you have obtained)
He knows that there are many places of interest in China. He knows that he cannot play all places in the T1 to t2 days, so he decided to designate two places V1, V2, if the contestant can calculate the total number of steps from V1 to v2 in the T1 to t2 days (including t1 and t2) (each road takes one day, and cannot stay in a city, and when T1 = 0, the number of walk is 0), t
Just list some of the mathematical theorems that have been used in the problem, and make a partial arrangement.1. The number of digits of N:LOG10 (N)2, N is prime number:A^m = a^ (m% (n-1)) (mod n)3, Euler function:The number that is smaller than the number of equals n, and n coprime number. Euler function Expression
≤n-2 and1:a^tmodn=12: Existence of integer i,0When n is a prime number, any A in 2 and n-1, a belongs to set B (n)When n is composite, if a belongs to set B (n), then n is a strong pseudo-prime number based on a (base), and a strong pseudo-evidence of N primality is called.N is a prime number, indicating that it is a strong pseudo prime for all the bottomBtest (a
is returned, it is not found once.
_ Int64 pollard_rov (_ int64 C, _ int64 N)
{
_ Int64 I, X, Y, K, D;
I = 1;
X = rand () % N;
Y = X;
K = 2;
Do
{
I ++;
D = gcd (N + Y-X, N );
If (D> 1 D
If (I = K) Y = X, K * = 2;
X = (product_mod (X, X, N) + N-C) % N;
} While (Y! = X );
Return N;
}
Find the minimum prime factor of N
_ Int64 Company (_ int64 N)
{
If (isprime (N) return N;
Do
{
_ Int64 T = maid (rand () % (N-1) + 1, N );
If (T
{
_ Int64 A, B;
A = rock (T );
B = rock (N/T );
Return A
}
}
While
Question: "I don't know the number of things today. There are two things left in three, three in five, three in five, and two in seven. Ask ry ?"
According to today's statement: divide a number by 3 + 2, divide by 5 + 3, divide by 7 + 2, and find this number...
At present, I still don't understand Sun Tzu's theorem (China's surplus theorem). So I will give my own
A new change problem
Time Limit: 5000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)Total submission (s): 533 accepted submission (s): 265 Problem descriptionnow given two kinds of coins a and B, which satisfy that gcd (a, B) = 1. here you can assume that there are enough coins for both kinds. please calculate the maximal value that you cannot pay and the total number that you cannot pay.
Inputthe input will consist of a series of
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.