二次联通门 : 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. Luogu4233 射命丸文的笔记 DP、多项式求逆

    传送门 注意到总共有\(\frac{n!}{n}\)条本质不同的哈密顿回路,每一条哈密顿回路恰好会出现在\(2^{\binom{n}{2} - n}\)个图中,所以我们实际上要算的是强连通有向竞赛图的 ...

  2. ADO.NET 一般操作(c#)

    ADO.NET五大对象:SqlConnection.SqlCommand.SqlDataReader.SqlDataAdapter .DataSet ,其中SqlDataAdapter 不建议使用 一 ...

  3. Python2与Python3兼容

    Python2与Python3兼容 python3写的代码如何也能在pyhon2上跑?请无论如何加上这一句,python3没有啥影响 from __future__ import absolute_i ...

  4. Spring Boot(二)

    Spring MVC流程图 注册流程图: result代码: import java.io.UnsupportedEncodingException; import java.net.URLEncod ...

  5. java 堆 排序学习

    /** * <html> * <body> * <P> Copyright 1994 JsonInternational</p> * <p> ...

  6. .net core web API使用Identity Server4 身份验证

    一.新建一个.net core web项目作为Identity server 4验证服务. 选择更改身份验证,然后再弹出的对话框里面选择个人用户账户. nuget 安装Identity server相 ...

  7. C# 将Excel导出PDF

    1.安装所需包,使用nuget安装所需包 1.1.Spire.Xls 1.2.iTextSharp.text.pdf 2.Spire.Xls介绍 将Excel转换为PDF是一个很常用的功能,常见的转换 ...

  8. C# Microsoft.Office 操作Excel总结

     1.导入命名空间:  using Microsoft.Office.Interop.Excel; 2.如何打开已有excel文档,或者创建一个新的excel文档  Application app = ...

  9. iOS加密之AES

    心急的童鞋直接看这里Demo 运行之后可以去在线加密网站验证 AES(Advanced Encryption Standard)高级加密标准,又称Rijndael加密法,是美国联邦政府采用的一种区块加 ...

  10. 详解iOS的presentViewController(转)

    一.用途和相关概念iOS中显示ViewController的方式有两种push和modal,modal也叫模态,模态显示VC是iOS的重要特性之一,其主要用于有以下场景: - 收集用户输入信息- 临时 ...