ToJ 2991 simple task II secondary surplus

Source: Internet
Author: User

 

 

/** Toj2991.c ** created on: 2011-10-13 * Author: bjfuwangzhu * // returns an integer N and calculates the quadratic homogeneous equation x ^ 2 = 1 (mod n) in [0, n) number of solutions in the closed interval. Analysis: according to the description in concise number theory, if p is a prime number, the number of solutions for x ^ 2 = 1 (mod P ^ K) is as follows. If P = 2 and K = 1, the number of solutions is 1, K = 2, the number of solutions is 2, K> = 3, and the number of solutions is 4. When P> 2 and K> 0, the number of solutions is 2. Then the decomposition factor. */# Include <math. h> # include <stdio. h> # include <string. h> # define Nmax 46345int flag [Nmax], prime [Nmax], Plen; int pfactor [Nmax], cpfactor [Nmax], len_factor; void mkprime () {int I, j; memset (flag,-1, sizeof (FLAG); for (I = 2, Plen = 0; I <Nmax; I ++) {If (flag [I]) {Prime [Plen ++] = I ;}for (j = 0; (j <Plen) & (I * prime [J] <Nmax); j ++) {flag [I * prime [J] = 0; if (I % prime [J] = 0) {break ;}}} void findp Factor (int n) {int I, Te, CNT; Te = (INT) SQRT (N * 1.0); for (I = 0, len_factor = 0; (I <Plen) & (prime [I] <= tE); I ++) {If (N % prime [I] = 0) {CNT = 0; while (N % prime [I] = 0) {CNT ++; N/= prime [I];} pfactor [len_factor] = prime [I]; cpfactor [len_factor ++] = CNT ;}} if (n> 1) {pfactor [len_factor] = N; cpfactor [len_factor ++] = 1 ;}} void solve (int n) {int I, Res; If (n = 1) {puts ("0"); return;} findpfactor (N); for (I = 0, Res = 1; I <len_factor; I ++) {If (pfactor [I] = 2) {If (cpfactor [I]> = 3) {res = res * 4;} else {res = res * cpfactor [I] ;}} else {res = res * 2 ;}} printf ("% d \ n", Res);} int main () {# ifndef online_judgefreopen ("data. in "," r ", stdin); # endifint N; mkprime (); While (~ Scanf ("% d", & N), n) {solve (n) ;}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.