HDU 4910 hdoj problem about GCD bestcoder #3 fourth question

Source: Internet
Author: User

First, when M = 1, ANS = 0
For M> 1
Given that numbers from 1 to 1 have a mass of M, a group is formed on the Multiplication Modulo operation of M.
Ai = (1 <= A <M & gcd (a, m) = 1)
Therefore, for a, B = a ^ (-1) = inv (a) makes a * B = 1 (mod m)
There are two cases
A! = B. Then, in the final concatenation formula, a B appears once, multiplied by 1.
A = B then only one A is displayed in the final concatenation
In fact, all the AI concatenation of a = inv (a) is the answer.
Continue to consider if gcd (a, m) = 1 then gcd (m-a, m) = 1
Note M-A =-A (mod m)
Then a * (-a) =-(A * A) =-1 (mod m)
M! = 2, m-! = A (otherwise a = m/2, gcd (M, M/2) = M/2! = 1)
So a and-A always appear in pairs.
So when the number of solutions for a ^ 2 = 1 (mod m)/2 is an odd number, the answer is-1. If it is an even number, the answer is 1.
When M = 2, the obtained answer is 1 (because 1 and-1 are equivalent, there is a special problem)

Therefore, for M> 2, only the number of solutions a ^ 2 = 1 (mod m) is required to be a multiple of 4.

 

A ^ 2 = 1 (mod m) Equivalent Transformation
(a + 1) (A-1) = 0 (mod m)
assume M = P0 ^ K0 * P1 ^ K1 *... * PI ^ KI (PI is a prime number)
the original equation based on the Chinese Remainder Theorem is equivalent to the
equations (a + 1) (A-1) = 0 (mod PI ^ KI)
consider a single equation first:
pi> 2, (A + 1) and (A-1) there must be a PI and PI (otherwise PI % 2 = 0)
so the solution of this equation is + 1 (mod PI ^ KI)
when Pi = 2,
when k = 1, the equation is resolved to 1 (mod 2)
when k = 2, the equation is solved as ± 1 (mod 4)
K> 2 equation is solved as ± 1, (2 ^ (k-1) + 1 ), (2 ^ (k-1)-1) (mod 2 ^ K)
when the equations have only one equation
consider multiple equations and merge them
according to the Chinese Remainder theorem, the values of each formula are as follows, all cases have only one solution in the range.
so the number of solutions of the equations is the product of the number of solutions of each equation.
m> 2, the number of solutions is not a multiple of 4 (that is, 2) Only the following
m = 2 ^ 2 = 4
M = P ^ K (P! = 2 and is a prime number)
m = 2 * P ^ K (P! = 2, and it is a prime number)

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.