Given a non-negative integer num , repeatedly add all its digits until the result have only one digit.For example:Given num = 38 , the process is like: 3 + 8 = 11 , 1 + 1 = 2 . Since have only one 2 digit, return it.The problem is to find the number root of a number.The number root has a congruence property: A number with its
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
Bzoj mathematical Number Theory
Question: Find 1 ~ N! Medium and M! Ensure n> M.
I hate mathematics most...
Idea: n> M is ensured, so n! It must be m! . If an X is found to make gcd (x, M !) = 1, then gcd (x + M !, M !) = 1 must be true, gcd (x + K * m !, M !) = 1 (k> = 1) is also valid. The number of X is PHI (M !), Then the total
"Test Instructions" for the given a,b,c, put a number of weights on the left side of the balance, put a number of weight B weights on the right side of the balance, so that the balance at both ends of the weight difference is c. Set X a weight and y b weights to find the minimum value of x+y."Algorithmic" number theory
Remember the combination of the first few chapters.We learned O (n^2) approach, plus the inverse, and we'll have an O (n) approachNow comes the new question, if N and M are big,For example, C (n, m)% p, nSee no, N and M so big, but P is very small, we have to use this P(number theory is such a boring thing, if I let n=1e100,m=1e100,p=1e100 you have the ability to calculate for me ah (°-°), not the same as n
Uva-10375choose and Divide (number theory)Topic linksThe main idea: the value of C (p,q)/C (r,s).Problem-Solving ideas: The topic gives the formula: then the above equation is equivalent to (p!s! ( R-S)!) /(q! (p-q)!r!)Need to discover q! and p!/(P-Q)! The relationship, Enumeration 1: Q The value can correspond to get p. P-q + 1, the corresponding product is p!/(P-Q)! , similarly s! and (R-S)! /r! Also, so
#include Give you a number and find the largest exponent that he can represent a power.Analysis: Number theory. Directly enumerate all the bases in 50000.Note: 1. Pay attention to the case of negative numbers, first calculate the corresponding integer, in the inverse judgment; 2.log10 () function precision problem.UVa 10622-perfect p-th Powers (
, from east to West for the positive direction, the unit length of 1 meters, so that we get a first-to-last line. The starting point of setting Frog A is x, and Frog B's starting point coordinates are Y. Frog A can jump M m at a time, Frog B can jump n meters at a time, and two frogs will spend the same time jumping once. Latitude line total length l m. Now you have to find out how many times they have jumped before they meet.InputThe input includes only one line of 5 integer x,y,m,n,l, where X≠
Why do you always run intoExtended Euclidean algorithm(?∀?) Most annoying number theory.Looks like it's time to learn.Degree Niang encyclopedia says:First, Ax+by = GCD (A, B) the formula must have a solution ((?∀?). She said that according to the correlation theorem in number theory can prove, anyway I believe.So ax+by = GCD (A, b) * k must also have a solution (
) a total of how many ways to go? This walk the number is C (2n,n-1) because go to the lower right corner to take more than 2 steps, at the same time only walk 2n steps, then the right lower corner walk n+1 step, the program method is 2n election n-1.Legal number =c (2n,n)-C (2n,n-1);Method Two:It can also be equivalent to the number of shortest paths from point
This section is Rujia's "Algorithmic Competition Primer Classic" (first edition) Chapter III of Number theory and computational geometry, but do not need to use classical algorithms and templates to simulate the main
Title Link: Http://acm.hust.edu.cn/vjudge/contest/view.action?cid=48182#overview
Topic Analysis:
a.uva575 Simple simulation gives you a number that
, the following proposition is shown: for the collection zn={x_1,x_2,..., x_φ (N)}, consider the collection S = {ax_1 (mod n), ax_2 (mod n), ..., ax_φ (n) (mod n)} S = Zn 1) because A,n coprime, x_i also with n coprime, Ax_i is also bound to n coprime, so arbitrary x_i,ax_i (mod n) must be an element of Zn 2) For Zn in two elements x_i and X_ J, if X_i≠x_ J is ax_i (mod n) ≠ax_ J (mod n), this is obtained by a, n coprime and elimination law. So, obviously, S=ZN in this case, then (ax_1
analysis and observation, then we only need to be a certain number of each number of times to appear, and then calculate the sum of this bit, because each one on the total and are the same, It is only necessary to solve the rounding and 10 of the multiply to ensure the digits. It is worth mentioning that the data of this topic is very big, the variable that stores the answer is best to use unsigned long lo
I love learning, learning makes me happy.But maths makes me vomit blood.This article will be a rough summary of some basic number theory knowledge, and the blogger has done a number of mathematical knowledge of high-demand topics.But so far, bloggers have nothing to do, so there's basically nothing here.First, Euclidean algorithmSecond, expand Euclidean algorithm
1 int judge (int* X) {2 x[2]/= gcd (x[2], x[1]); 3 for (int3; I 2]/= gcd (x[i], x[2]); 4 return x[21; 5 }This algorithm is called Euclidean algorithm. will not overflow, because
gcdThe number of recursive layers of a function does not exceed4.785lgN+ 1.6723ItsInN=max{a,b}。LetgcdThe highest number of recursive layers isgcdF n , F n -1). The GCD can also be used to find the least common multiple LCM
); * for(intI=1; i) $ {Panax Notoginseng if(cnt[i]==cnt[i-1]) - { theans++; + if(ans==k) A { theprintf"%d", Cnt[i]); + return 0; - } $ } $ Elseans=1; - } - the return 0; -}View Codemore about the bezout theorem
In number theory, the Bezout theorem is a t
Expand EuclidThe last time I finished the Euclid, there is a thing called expanding Euclid:Expanding Euclid is a good way to solve problems such as congruence, and its specific functions are as follows:When known (A, b), the Solve group (P,Q) makes the P*A+Q*B=GCD (A, B)First of all, according to the principle of number theory, the solution must exist.We can set a for a multiple of gcd (A, a, a, a, b) is k,
Topic Link: Click to open the linkProblem Solving Ideas:Use the knowledge of number theory, or you might want Java to open large numbers In view of my Java is so weak, still use mathematics knowledge!(I * i * i * *i)% m = = (((i% m) * I% m) )%m. In short, do not forget the end of the cycle after the M to take more than once.Full code:#include More highlights please visit: Click to open the linkUral1110 (
Huge Fibonacci Numbers!The main idea: Fibonacci series F[n], give you a,b,n, beg f[a^b]%n.Idea: Number theory problem. F[a^b]%n is a cycle, we can find out this cycle will be simplified into f[(a% cycle ) ^b]% cycle by the use of the division of the power to take the model.Note with unsigned long long (seemingly a long long twice times), or will overflow, and learned a trick ...Do not know which bug, has b
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.