End; thee:=Next[e]; + End; - End; $ $ functionmi (x,y:int64): Int64; - varTmp:int64; - begin themi:=1; tmp:=x; - whileY>0 DoWuyi begin the ifY and 1=1 ThenMi:=mi*tmpMoDmo; -Tmp:=tmp*tmpMoDmo; WuY:=y>>1; - End; About End; $ - functionexf (X:int64): Int64; - begin -Exit (MI (x,mo-2)); A End; + the begin -Assign (input,'forest.in'); Reset (input); $Assign (output,'Forest.out'); Rewrite (output); the READLN (n); the fori:=1 toN Do the begin the read (a[i]); -f[i]:=A[i]; in End; t
: There are many solutions to the indefinite equations calculated by expanding the Euclidean, the final inverse should be x%n, that is, the range of the inverse is [0,n-1]Multiply inverse of ax≡1 (mod n), if not present, returns-1Long long inverse (long long a,long longn){Long long x, y;if (EXTENDED_GCD (a,n,x,y) ==1) return (x+n)%n; else return-1;}After EXTENDED_GCD () is executed, x may be negative, and N will become an integer. TakeModulo operations have a rate of allocation for addition, sub
Hdu 4983 Goffi and GCD (number theory), hdugoffi
Link: hdu 4983 Goffi and GCD
Question: How many pairs of tuples meet the formula in the question.
Solution:
When n = 1 or k = 2: the answer is 1.
K> 2: the answer is 0 (n = 1)
K = 1: Calculate the factor of n, so that the factor k = gcd (n −a, n, then the gcd of the other side (n −b, n) = nk can satisfy the multiplication of n, and the
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4059
A high pass rate in the competition, but the principle of rejection is not very good ..
Reference http://blog.csdn.net/acm_cxlove/article/details/7434864
1. Calculate the inverse element P = 1e9 + 7 is the prime number, so the inverse element of a % P obtained from a ^ (p-1) % P with the remainder of 1 is a ^ (P-2)
2. segma (I ^ K) can obtain the summation formula by derivation. For details, see htt
Given N and K integers, find a subgroup G' of group G under mod n addition, satisfying a [1] ~ A [k-1] is not in the group and a [k] is in the group
First, the certificate G' must be a cyclical group.
Proof: Apparently, if A is in the group, the reverse element of A is in the group.
Then we have the subtraction operation.
From the closeness of the group, if both A and B are in the group, gcd (a, B) must be in the group.
Set G to the GCD of all elements in G. Then the group g'' = {0, G, 2g,...}
Label: style blog color Io for SP Div log amp
O (SQRT (N) refers to the approximate number, which is determined based on the definition of brute force.
1 # include
[Number Theory] [enumeration approx.] [friendly count] codevs 2632 friends
1 // accepted 168 KB 969 MS 2 // n! The number of P containing the prime factor is t = N/P + N/P ^ 2 + N/P ^ 3 +... 3 # include View code
1 //Accepted 900 KB 344 ms 2 #include View code
Poj1992 Number Theory
Codeforces 490D Chocolate Number Theory
Portal: cf 490D
There are two rectangles. Now you can perform two operations on the rectangle.
(1) Remove the rectangle by half (if one side is half of the original one, this side is required to be divisible by two)
(2) Remove the rectangle by 1/3 (one side is changed to the original 2/3, which requires that the side be divisible by 3)
How many operations can be perfo
useless state of the original enumeration is removed by mathematical operation;Code:1#include 2#include 3#include 4#include string>5#include 6#include 7#include 8#include 9#include Set>Ten#include One#include A using namespacestd; - #defineFILE "Dealing" - #defineLL Long Long the #defineUp (I,j,n) for (int i=j;i - #definePII pair - #definePIII pair -TemplateBOOLChkmin (T a,t b) {returnA>b?a=b,true:false;} + namespaceio{ - Char*fs,*ft,buf[1 the]; +InlineCharGC () {return(fs==ft (ft= (fs=bu
Set M is a positive integer, A is an integer, if the order of a-mode m is equal to φ (m), then A is called a primary root of modulo m. (where φ (m) represents the Euler function of M) gives 1 prime number p and finds the minimum root of P. InputInput of 1 prime numbers p (3 OutputThe minimum root of the output p.Input example3Output example2Solution: Use the fast power to be careful when int explodes.1#include 2#include 3 4 #defineCLR (x) memset (x,0,
CubeTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)Total submission (s): 1516 Accepted Submission (s): 1206Problem Descriptioncowl is good at solving math problems. One day a friend asked him such a question:you be given a cube whose edge length is N, it's cut by the planes Paralleled to it side planes into n * n * n unit cubes. Both unit cubes may have no common points or both common points or four common points. Your job is to calculate how many pairs of unit c
Funny Scales problem ' s Link---------------------------------------------------------------------------- Mean:Given two numbers n and X, there is a balance, initially Zopan X, you need to select some numbers from the following set to two disks, making two disks equal (note: Each number can only be taken once). Analyse:ThatTurn X into 3 binary:But the topic says that each 3^i must be 1, so we need to change the coefficients of each of the equations
we'll be able to linear recursion ... Then the inverse element of 1~n is introduced.3. CRTCRT is the solution X≡bi (mod pi) for a congruence equation group ... Previously it had been written by the violent CRT (violence to do addition ...).But if we think so ... x = a1 + A2 + A3, where only AI contributes to equation I (ai% pj! = i) = = 0This is a good thing to do, to use EXGCD to find out each AI, and then sum to get an X solution.4. Lucas Ex_lucas.Lucas:c (n,m)% P = = C (n p, m% p) * Lucas (
To a chessboard, need to go from the upper left to the lower right corner, some points can not go, to find a total number of ways to go.The first thing to know is how many ways to go from one point A to another, B, without obstacles. Make sure A is at the top left of B,There is a total need to walk (x+y) step (x, y in the picture), in which the X-step to the horizontal, the Y-step vertical direction. So a total of C (x+y, X) species go.Arrange all the
What is called derivation equation? To solve such a problem is to say plainly:A^x=b (mod C) to find the minimum x value.
Baby Step giant Step algorithmTitle Condition: C is prime ( in fact, A and C coprime can. Why? In the BSGS algorithm is required a^m in the%c condition of the inverse element, if a, C is not coprime there is no inverse element. )If X has a solution, then 0We can recall the Euler theorem:For cases where C is a prime number, φ (
Topic PortalTest instructions: There is a finite fraction of a in, Q can be converted to a finite fraction of B-decimalAnalysis: 0.123 is expressed in a binary: 1/a + 2/(a^2) + 3/(a^3), converted to B-system is continuously multiplied by B until 0, i.e. (1/a + 2/(a^2) + 3/(A^3)) * (B^M). Then (b^m) must be divisible (a^n), conversion is a of the quality factor B has, you can use the GCD efficient calculationHarvest: The number of topics can not do to
in the problem.Common E[k] Indicates the desired number of steps to reach the target node from the K-node, so the target node p, e[p]=0, is critical.Constructs the equation group, brings into the template.Integer Gaussian elimination Template:Gaussian elimination template #include Floating-point Gaussian elimination Template:#include A topic of integral Gaussian elimination: http://blog.csdn.net/sr_19930829/article/details/38959149A topic of floating
The topic is: Given A1,A2,..., an, askSince φ is an integrable function, we can decompose the i1i2...in into factorization, and for each factorization to be discussed separately, the quadrature can beFactorization each a decomposition, assuming that the number of times that a prime p is decomposed is bi in each AI, then P's contribution to the answer isSo the p^j maintain a prefix and, directly calculate can#include Bzoj 3560 Dzy Loves Math V
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.