bzoj 1406: [AHOI2007]密码箱 二次剩餘
1406: [AHOI2007]密码箱
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 701 Solved: 396
[Submit][Status]
Description
Input
Output
Sample Input
Sample Output
5
7
11
HINT
Source
題解傳送門:http://www.cnblogs.com/htfy/archive/2012/12/11/2813448.html
這道題思路比較獨特,運用了平方差公式解二次剩餘。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<string>
#include<queue>
using namespace std;
#ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif
#define MAXN 1100
#define MAXV MAXN*2
#define MAXE MAXV*2
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
typedef long long qword;
inline int nextInt()
{
char ch;
int x=;
bool flag=false;
do
ch=(char)getchar(),flag=(ch=='-')?true:flag;
while(ch<''||ch>'');
do x=x*+ch-'';
while (ch=(char)getchar(),ch<='' && ch>='');
return x*(flag?-:);
} int n,m;
vector<int> vec;
int main()
{
freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int i,j,k;
qword x,y,z;
scanf("%d",&n);
//x^2==1 (mod n)
//x^2-1 == k*n
//(x+1)(x-1)==k*n
//n = a*b
//a|(x+1) b|(x-1)
qword a,b;
for (a=;a*a<=n;a++)
{
if (n%a!=)continue;
b=n/a;
for (x=;x<n;x+=b)
if ((x+)%a==)
vec.push_back(x);
for (x=b-;x<n;x+=b)
if ((x-)%a==)
vec.push_back(x);
}
sort(vec.begin(),vec.end());
vector<int>::iterator it1,it2;
// it1=vec.end();
it1=unique(vec.begin(),vec.end());
for (it2=vec.begin();it2!=it1;it2++)
{
printf("%d\n",*it2);
}
return ;
}
bzoj 1406: [AHOI2007]密码箱 二次剩餘的更多相关文章
- BZOJ 1406: [AHOI2007]密码箱
二次联通门 : BZOJ 1406: [AHOI2007]密码箱 /* BZOJ 1406: [AHOI2007]密码箱 数论 要求 x^2 ≡ 1 (mod n) 可以转换为 x ^ 2 - k * ...
- BZOJ 1406: [AHOI2007]密码箱( 数论 )
(x+1)(x-1) mod N = 0, 枚举N的>N^0.5的约数当作x+1或者x-1... ------------------------------------------------ ...
- BZOJ 1406: [AHOI2007]密码箱 exgcd+唯一分解定理
推出来了一个解法,但是感觉复杂度十分玄学,没想到秒过~ Code: #include <bits/stdc++.h> #define ll long long #define N 5000 ...
- 1406: [AHOI2007]密码箱
1406: [AHOI2007]密码箱 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1591 Solved: 944[Submit][Status][ ...
- 【BZOJ】1406: [AHOI2007]密码箱
http://www.lydsy.com/JudgeOnline/problem.php?id=1406 题意:求$0<=x<n, 1<=n<=2,000,000,000, 且 ...
- BZOJ_1406_[AHOI2007]密码箱_枚举+数学
BZOJ_1406_[AHOI2007]密码箱_枚举+数学 Description 在一次偶然的情况下,小可可得到了一个密码箱,听说里面藏着一份古代流传下来的藏宝图,只要能破解密码就能打开箱子,而箱子 ...
- 洛谷——P4296 [AHOI2007]密码箱
P4296 [AHOI2007]密码箱 密码x大于等于0,且小于n,而x的平方除以n,得到的余数为1. 求这个密码,$1<=n<=2,000,000,000$ 暴力枚举,数据有点儿水$O( ...
- 【BZOJ 1406】 [AHOI2007]密码箱
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] \(x^2%n=1\) \(x^2-1 = k*n\) \((x+1)*(x-1) % n == 0\) 设\(n=a*b\) 对于 ...
- BZOJ 1406 密码箱
直接两层枚举就行了. 避免排序可以用set. #include<iostream> #include<cstdio> #include<cstring> #incl ...
随机推荐
- SQL2008和SQL2000可以跨服务器连接查询的测试实例
测试目的: SQL2008 和 SQL2000 是否可以跨服务器连接查询 -- 测试环境: --A 虚拟机 XP ( IP : .0.0.213 )安装 SQL2000 个人版,并安装 SP4 补丁. ...
- 单表扫描,MySQL索引选择不正确 并 详细解析OPTIMIZER_TRACE格式
单表扫描,MySQL索引选择不正确 并 详细解析OPTIMIZER_TRACE格式 一 表结构如下: 万行 CREATE TABLE t_audit_operate_log ( Fid b ...
- Hack工具
黑客工具一般是由黑客或者恶意程序安装到您计算机中,用来盗窃信息.引起系统故障和完全控制电脑的恶意软件程序.同时也指黑客进行黑客任务时使用的工具.著名的有nmap,流光等等. 目录 1 种类 2 恶意程 ...
- hdu2047.java递推题
阿牛的EOF牛肉串 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- CSS hack常用方案(摘选)
邮箱因为默认了line-height?:170%,导致采用table元素时继承问题,可以采用line-height:50% 很好解决. 常 在使用float时,后面的显示不正常,因为继承了float了 ...
- 关于js中伪数组
伪数组: 具有length属性: 按索引方式存储数据: 不具有数组的push().pop()等方法: 伪数组无法直接调用数组方法或期望length属性有什么特殊的行为,不具有数组的push().pop ...
- ubuntu 14.04 编译安装 nginx
下载源码包 nginx 地址:http://nginx.org/en/download.html 下载nginx 1.4.7 编译前先安装两个包: 直接编译安装会碰到缺少pcre等问题,这时候只要到 ...
- CentOS 6.7安装配置Ansible
1.准备CentOS环境 yum update && yum upgrade 2.控制服务器与被管理服务器要求 Master:Python 2.6+ Slave:Python 2.4+ ...
- Java动态调用webService,axis2动态调用webService
Java动态调用webService axis2动态调用webService >>>>>>>>>>>>>>>& ...
- JDK自带方法实现RSA非对称加密
package jdbc.pro.lin; import java.security.InvalidKeyException; import java.security.Key; import jav ...