NEU 1440 the minimum square sum (square remainder and Euler's criterion)

Source: Internet
Author: User

If P = 2 or P = 4 * k + 1, P can be expressed in the form of the sum of two degrees (Euler and ferma have proved and have an exact method). Therefore, the answer is P.

If P = 4 * k + 3, set a ^ 2 = N (mod p) (n! = 0) it can be proved that there is no B, B ^ 2 = p-n (mod p). That is, if n is the square residue of p, p-n is not the square residue of P.

Proof: because a ^ 2 = N (mod P), N ^ (p-1)/2) = 1 (mod P) is obtained by Euler's criterion)

If B ^ 2 =-N (mod p) Then (-N) ^ (P-1/2) = 1 (mod P)

Put the symbol (-1) ^ (P-1/2) * n ^ (p-1)/2) on the left)

Because p is 4 * k + 3 type, the value of P (P-1)/2 is an odd number, so the left side cannot be equal to 1.

So a ^ 2 = 0 (mod p) B ^ 2 = 0 (mod p) so the answer is 2 * p * P

 
# Include <bits/stdc ++. h> using namespace STD; int main () {long P; while (scanf ("% LLD", & P) = 1) {If (P = 2 | P % 4 = 1) printf ("% LLD \ n", P); else printf ("% LLD \ n ", p * 2);} return 0 ;}


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.