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 ...
随机推荐
- 晕,hibernate 的 merge和cascade="all-delete-orphan"要慎重合在一起使用
遇到一个比较后悔莫及事情,使用了hibernate 的 merge和cascade="all-delete-orphan" ,子表数据被删除了. 1.使用cascade=" ...
- MYSQL 系统命令 源码定位
sql_cmd.h enum enum_sql_command { SQLCOM_SELECT, SQLCOM_CREATE_TABLE, SQLCOM_CREATE_INDEX, SQLCOM_AL ...
- JAVA对象之生
https://yq.aliyun.com/users/1556056716932876?spm=5176.100239.blogrightarea55811.3.6cvyJd
- 40多个非常有用的Oracle 查询语句
给大家介绍是40多个非常有用的Oracle 查询语句,主要涵盖了日期操作,获取服务器信息,获取执行状态,计算数据库大小等等方面的查询.这些是所有Oracle 开发者都必备的技能,所以快快收藏吧! 日期 ...
- JS事件监听 JS:attachEvent和addEventListener 使用方法
attachEvent与addEventListener区别适应的浏览器版本不同,同时在使用的过程中要注意attachEvent方法 按钮onclickaddEventListene ...
- NPOI的使用
简介:NPOI是POI(APATCH的一个开源项目)项目的.NET版本,最初的POI只用于JAVA来操作EXCEL or WORD等微软OLE2组件项目.使用NPOI可以完成在你没有安装Office或 ...
- Graphics类绘制图形
1. 画直线 void drawLine(int startX,int startY,int endX,int endY); 四个参数分别为:起始点的x坐标和y坐标以及终点的x坐标和y坐标,该方法用于 ...
- C/C++中文的编码和字符串处理
windows平台 char 表示单字符,占用一个字节 wchar_t 表示宽字符,占用两个字节 Linux平台 char 占用一个字节 wchar_t 占用四个字节 windows平台下对于用字符串 ...
- Codeforces 553D Nudist Beach(图论,贪心)
Solution: 假设已经选了所有的点. 如果从中删掉一个点,那么其它所有点的分值只可能减少或者不变. 如果要使若干步删除后最小的分值变大,那么删掉的点集中肯定要包含当前分值最小的点. 所以每次删掉 ...
- 编写类String的构造函数、拷贝构造函数、析构函数和赋值函数
一.题目: class String { public: String(const char *str = NULL); // 普通构造函数 String(const String &othe ...