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 ...
随机推荐
- COCOS2D-X 精灵创建随笔
CCSprite类中创建Sprite的方法都是静态的: static CCSprite* create ( ) 创建一个无图片显示的精灵,可随后用 setTexture 方法设置显示图片 stati ...
- mac下mysql5.6字符集设置
http://geeksblog.cc/2016/05/28/mac-mysql-unicode/ mac下mysql5.6字符集设置: 在mac下设置mysql5.6字符集时踩过的坑,百分百保证 ...
- Load Balance Tomcat with Nginx and Store Sessions in Redis--reference
An awkward title, but that’s exactly what we’re going to do. For some time, I was looking for a way ...
- linux常用的压缩与解压缩命令 分类: 学习笔记 linux ubuntu 2015-07-05 19:38 38人阅读 评论(0) 收藏
1.gzip 压缩 gzip 是压缩文件,压缩之后文件后缀为.gz 用法:gzip 选项 [文件] 2.gunzip 解压 这个命令与gzip的功能刚好相反,这个是解压. 用法 gunzip 选项 [ ...
- DOS和UNIX文本文件之间相互转换的方法
在Unix/Linux下可以使用file命令查看文件类型,如下: file dosfile.txt 使用dos2unix 一般Linux发行版中都带有这个小工具,只能把DOS转换为UNIX文件,命令如 ...
- Linux查看某个文件被哪些进程PID占用
比如查看test.sh这个文件被哪些进程占用,可以用: lsof | grep test.sh 或者 fuser -v test.sh
- index页面数据展示为设定的命名
数据库表里面字段的值想用另一种命名形式展示,如1是 是,2是 否 解决方法: 用到formatter ,{field: 'params', title: '参数', width: 100, sort ...
- phpstrtotime()对于31日求上个月有问题
PHP自带的strtotime()对于31日求上个月有问题,如下: <?php $date = "2012-07-31"; $date_unix = strtotime($d ...
- Js 命名空间注册方法
MyApp = { namespace: function () { var a = arguments, o = null, i, j, d, rt; for (i = 0; i < a.le ...
- shiro认证
一.通过ini文件初始化一个用户 1.通过ini配置文件创建securityManager2.调用subject.login方法主体提交认证,提交的token3.securityManager进行认证 ...