/** 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 ;}