您的位置:首页 > 其它

BZOJ 1406: [AHOI2007]密码箱

2017-09-07 19:12 417 查看
二次联通门 : BZOJ 1406: [AHOI2007]密码箱

/*
BZOJ 1406: [AHOI2007]密码箱

数论
要求 x^2 ≡ 1 (mod n)
可以转换为 x ^ 2 - k *n = 1
(x + 1) * (x - 1) = k * n
设 n = a * b
则 a * b | (x + 1) * (x - 1)
那么枚举b即可
*/
#include <cstdio>
#include <cmath>
#include <set>
typedef long long LL;
#define Set std :: set <LL>

int main ()
{
LL N, a, b; scanf ("%lld", &N); register LL i, j;
int L = sqrt (N); Set Answer;
for (i = 1; i <= L; ++ i)
if (N % i == 0)
{
a = i, b = N / i;
for (j = 0; j <= N; j += b)
{
if ((j + 2) % a == 0 && j + 2 < N) Answer.insert (j + 1);
if ((j - 2) % a == 0 && j - 2 >= 0) Answer.insert (j - 1);
}
}
if (Answer.size () == 0) return printf ("None"), 0;
for (Set :: iterator i = Answer.begin (); i != Answer.end (); ++ i)
printf ("%lld\n", *i);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: