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 ...
随机推荐
- 史上比较用心的纯代码实现 AutoLayout
入职有两三个月了吧,都是使用 Objective-C 纯代码(虽然有时候偷偷参杂一些 Swift 开源库)来编写公司APP,写布局的时候几乎都是要么在初始化的时候用 initWithFrame,要么就 ...
- 打造强势智能手表平台:Testin云測携手索尼招募全球开发人员
打造强势智能手表平台:Testin云測携手索尼招募全球开发人员 2014/10/27 · Testin · 业界资讯 日前,全球最大的移动游戏.应用真机和用户云測试平台Testin云測宣布联手索尼公司 ...
- Win32下 Qt与Lua交互使用:配置Qt下Lua运行环境
Lua与C++之间可以实现非常强的交互性.Lua中可以使用C++中的函数,C++中也可以使用Lua中的函数.由此可以引发出很多奇思妙想了. 简单来说,Lua动态的特性补充了C++的功能.当然,也看你具 ...
- android js 互调
public class BoatsActivity extends Activity { Handler mHandler = new Handler();//处理消息的handler @Suppr ...
- WPF Radio组的绑定
都是控件编,RadioButtion 简单绑定使用,model.cs下边定义属性 private int _isSuccess; public int IsSuccess { get { return ...
- python查看网站的RTT
import requests time=0.0 jpserver=['jp1.herejump.com','jp1.herejump.com','jp1.herejump.com'] usserve ...
- Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException
异常Log: Error:Execution failed for task ‘:app:dexDebug’. > com.android.ide.common.process.ProcessE ...
- java中获得IP地址
public class IPTest { public static void main(String[] args) { try{ // 获取计算机名 String name = InetAddr ...
- MSSQL备份及数据迁移
版本:MSSQL 2008 备份情景:从A服务器的SQL 迁移到B服务器,并且数据也迁移过去. 操作环境:A服务器:WINDOWS7 B服务器:WINDOWS8.1 辅助工具:VNC 首先从A服 ...
- 使用DataList 分页方法
什么是DataList我想应该不需要解释了,接下来分享本人在项目里使用到的通过DataList进行分页展示方法. 首先在ASPX页面添加一个DataList(后面都简称DL)控件,示例代码如下: &l ...