1406: [AHOI2007] Lockbox time limit:5 Sec Memory limit:64 MB
submit:1143 solved:677
[Submit] [Status] [Discuss] Description in an accidental situation, can get a password box, I heard that there is a copy of the ancient Tibetan treasure map, as long as you can crack the password can open the box, and the back of the box engraved on the ancient icon, is the hint of the password. After hard deciphering, little cocoa found that these icons represent a number and the relationship between this number and the password. Assuming that this number is n, the password is x, then you can get the following expression: Password x is greater than or equal to 0, and is less than n, and x squared divided by N, the remainder is 1. Little cocoa knows that there may be more than one x that satisfies the above conditions, so be sure to calculate all the x that satisfies the condition, and the password must be in it. The process of calculation is very difficult, can you write a program to help small cocoa? (X,n are all positive integers in the title) input file has only one row and only a number n (1<=n<=2,000,000,000). Output your program needs to find all the x that satisfies the conditions described above, if there is no such x, your program just output a line "None" (quotation marks do not output), otherwise please follow the order from small to large to export these x, one number per line. Sample Input12
Sample Output1
5
7
11
Hintsource
Solution
Test instructions is very simple, $x ^{2}\equiv 1\left (mod n \right) $ on $\left [1,n\right] $ on all solutions
Convert: $x ^{2}= kxn+1$
$x ^{2}-1=kxn$
$ (x+1) (x-1) =kxn$
So make $x+1=k ' xn ', x-1=k ' xn ' $ meet $k ' xk ' =k,n ' xn ' =n$
Then find the approximate number of N, enumerate more than $\sqrt n$ and judge the approximate
The answer will be repeated, need to go to the heavy, here apply set
Code
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<Set>using namespacestd;intn,gn;intys[44722],zz;Set<int>ans;intMain () {scanf ("%d", &n); gn=sqrt (n); for(intI=1; i<=gn; i++) if(! (n%i) &&! (n% (n/i)) ys[++zz]=n/i;//for (int i=1; i<=zz; i++) printf ("%d", ys[i]); for(intI=1; i<=zz; i++) for(Long LongJ=ys[i]; j<=n; j+=Ys[i]) { if(! ((j+2)% (N/ys[i])) Ans.insert (int(j+1)%N); if(! (J-2)% (N/ys[i])) Ans.insert (int(J-1)%N); } if(Ans.empty ()) puts ("None"); Else while(!ans.empty ()) printf ("%d\n",*Ans.begin ()), Ans.erase (Ans.begin ()); return 0;}
The use of set is not very skilled, thank HJXCPG a few words of help ... Ta ye seems to have a password box reinforced version, it seems not to do .... I'm strong.
"BZOJ-1406" cipher box approximate + WTF + set?