Problem
给你1个数n,求出0 ≤ x < n,并且x ^ 2 % n = 1
Solution
x ^ 2 - 1 = kn,(x - 1) * (x + 1) = kn
所以枚举n的约束,是x-1或者x+1,然后看是否符合条件
Notice
注意要排序去重
Code
#include<set>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define sqz main
#define ll long long
#define reg register int
#define rep(i, a, b) for (reg i = a; i <= b; i++)
#define per(i, a, b) for (reg i = a; i >= b; i--)
#define travel(i, u) for (reg i = head[u]; i; i = edge[i].next)
const int INF = 1e9, N = 60005;
const double eps = 1e-6, phi = acos(-1.0);
ll mod(ll a, ll b) {if (a >= b || a < 0) a %= b; if (a < 0) a += b; return a;}
ll read(){ ll x = 0; int zf = 1; char ch; while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;}
void write(ll y) { if (y < 0) putchar('-'), y = -y; if (y > 9) write(y / 10); putchar(y % 10 + '0');}
set<int> C;
int cnt = 0;
int T[N];
int sqz()
{
int n = read();
rep(i, 1, (int)sqrt(n))
{
if (n % i) continue;
int Cha = n / i, T = 1;
while (T <= n)
{
if ((T + 1) % i == 0) C.insert(T);
T += Cha;
}
T = Cha - 1;
while (T <= n)
{
if ((T - 1) % i == 0) C.insert(T);
T += Cha;
}
}
for (set<int>::iterator i = C.begin(); i != C.end(); i++) printf("%d\n", *i);
}