码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ 1406: [AHOI2007]密码箱

时间:2017-09-07 20:28:38      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:gis   iter   cst   style   none   main   ==   scanf   nbsp   

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

 

BZOJ 1406: [AHOI2007]密码箱

标签:gis   iter   cst   style   none   main   ==   scanf   nbsp   

原文地址:http://www.cnblogs.com/ZlycerQan/p/7491352.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!