二次联通门 : 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 = ; i <= L; ++ i)
if (N % i == )
{
a = i, b = N / i;
for (j = ; j <= N; j += b)
{
if ((j + ) % a == && j + < N) Answer.insert (j + );
if ((j - ) % a == && j - >= ) Answer.insert (j - );
}
}
if (Answer.size () == ) return printf ("None"), ;
for (Set :: iterator i = Answer.begin (); i != Answer.end (); ++ i)
printf ("%lld\n", *i);
return ;
}

BZOJ 1406: [AHOI2007]密码箱的更多相关文章

  1. bzoj 1406: [AHOI2007]密码箱 二次剩餘

    1406: [AHOI2007]密码箱 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 701  Solved: 396[Submit][Status] D ...

  2. BZOJ 1406: [AHOI2007]密码箱( 数论 )

    (x+1)(x-1) mod N = 0, 枚举N的>N^0.5的约数当作x+1或者x-1... ------------------------------------------------ ...

  3. BZOJ 1406: [AHOI2007]密码箱 exgcd+唯一分解定理

    推出来了一个解法,但是感觉复杂度十分玄学,没想到秒过~ Code: #include <bits/stdc++.h> #define ll long long #define N 5000 ...

  4. 1406: [AHOI2007]密码箱

    1406: [AHOI2007]密码箱 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1591  Solved: 944[Submit][Status][ ...

  5. 【BZOJ】1406: [AHOI2007]密码箱

    http://www.lydsy.com/JudgeOnline/problem.php?id=1406 题意:求$0<=x<n, 1<=n<=2,000,000,000, 且 ...

  6. BZOJ_1406_[AHOI2007]密码箱_枚举+数学

    BZOJ_1406_[AHOI2007]密码箱_枚举+数学 Description 在一次偶然的情况下,小可可得到了一个密码箱,听说里面藏着一份古代流传下来的藏宝图,只要能破解密码就能打开箱子,而箱子 ...

  7. 洛谷——P4296 [AHOI2007]密码箱

    P4296 [AHOI2007]密码箱 密码x大于等于0,且小于n,而x的平方除以n,得到的余数为1. 求这个密码,$1<=n<=2,000,000,000$ 暴力枚举,数据有点儿水$O( ...

  8. 【BZOJ 1406】 [AHOI2007]密码箱

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] \(x^2%n=1\) \(x^2-1 = k*n\) \((x+1)*(x-1) % n == 0\) 设\(n=a*b\) 对于 ...

  9. BZOJ 1406 密码箱

    直接两层枚举就行了. 避免排序可以用set. #include<iostream> #include<cstdio> #include<cstring> #incl ...

随机推荐

  1. appium实例1:启动淘宝app

      1.在android-sdk里面双击SDK-manager,下载buidl-tools 2.勾选build-tools,随便选一个版本,我这里选的是24的版本 3.下载完成后,在D:\androi ...

  2. tkinter学习笔记_04

    8.勾选项 checkbutton import tkinter as tk root = tk.Tk() root.title("xxx") root.geometry('200 ...

  3. 额。。。c++ sort()排序问题

    首先呢 记得 这是个快排 不稳定 基本格式 头文件 #include<algorithm> #include<iostream> bool cmp(int x,int y) { ...

  4. .Net 取树形结构的数据

    最近遇到了无限层级数据要读取的问题,所有就写了个. 根据当前所有父级,查询出子级内容 private void GetTypeOfWorkforTree(out List<TypeOfWorkD ...

  5. vs2012配置gitHub管理代码详细步骤

    http://www.bitscn.com/pdb/otherdb/201411/411244.html

  6. MySQL Index--关联条件列索引缺失导致执行计划性能不佳

    某系统反馈慢SQL影响生产,查看SLOW LOG发现下面慢SQL: SELECT COUNT(DISTINCT m.batch_no) FROM ob_relation r INNER JOIN ob ...

  7. 基于Java的支持可变QPS的http负载生成器,提供交互界面和RMI接口

    Load generator The load generator is a Java maven project which is implemented using httpclient+thre ...

  8. koa2安装

    安装 1. npm install koa-generator -g 2. Koa2 test-koa2 3. npm install & npm run dev 看package.json里 ...

  9. JQuery实现品牌展示

    最近验收了ITOO,老师当时验收的时候对于界面的设计非常敏感,只要看了一个大体轮廓,就能给出我们建议,这是二十年积累的经验,我们要做的就是站在巨人的肩膀上,让我们成长更快! 老师说了一下关于界面设计的 ...

  10. scala 基础知识 FAQ

    问题1: 抽象成员初始化规则 ① 父类先初始化 ② 在初始化的过程中,如果 val 发生重写,只有最后一个重写生效.前面的会变成零值,后面的会直接继承. 参考资料:https://docs.scala ...