BZOJ 1406: [AHOI2007]密码箱

二次联通门 : 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;
}

 

posted @ 2017-09-07 19:12  ZlycerQan  阅读(206)  评论(0编辑  收藏  举报