Problem

给你1个数n,求出0 ≤ x < n,并且x ^ 2 % n = 1

Solution

x ^ 2 - 1 = kn,(x - 1) * (x + 1) = kn

所以枚举n的约束,是x-1或者x+1,然后看是否符合条件

Notice

注意要排序去重

Code

#include<set>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define sqz main
#define ll long long
#define reg register int
#define rep(i, a, b) for (reg i = a; i <= b; i++)
#define per(i, a, b) for (reg i = a; i >= b; i--)
#define travel(i, u) for (reg i = head[u]; i; i = edge[i].next)
const int INF = 1e9, N = 60005;
const double eps = 1e-6, phi = acos(-1.0);
ll mod(ll a, ll b) {if (a >= b || a < 0) a %= b; if (a < 0) a += b; return a;}
ll read(){ ll x = 0; int zf = 1; char ch; while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;}
void write(ll y) { if (y < 0) putchar('-'), y = -y; if (y > 9) write(y / 10); putchar(y % 10 + '0');}
set<int> C;
int cnt = 0;
int T[N];
int sqz()
{
int n = read();
rep(i, 1, (int)sqrt(n))
{
if (n % i) continue;
int Cha = n / i, T = 1;
while (T <= n)
{
if ((T + 1) % i == 0) C.insert(T);
T += Cha;
}
T = Cha - 1;
while (T <= n)
{
if ((T - 1) % i == 0) C.insert(T);
T += Cha;
}
}
for (set<int>::iterator i = C.begin(); i != C.end(); i++) printf("%d\n", *i);
}

[BZOJ1406]密码箱的更多相关文章

  1. 【BZOJ-1406】密码箱 约数 + 乱搞 + set?

    1406: [AHOI2007]密码箱 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1143  Solved: 677[Submit][Status][ ...

  2. BZOJ1406 [AHOI2007]密码箱 数论

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1406 题意概括 求所有数x,满足 x<n 且 x2≡1 (mod  n). n<=2 ...

  3. 【bzoj1406】 AHOI2007密码箱 数论

    在一次偶然的情况下,小可可得到了一个密码箱,听说里面藏着一份古代流传下来的藏宝图,只要能破解密码就能打开箱子,而箱子背面刻着的古代图标,就是对密码的提示.经过艰苦的破译,小可可发现,这些图标表示一个数 ...

  4. [BZOJ1406][AHOI2007]密码箱(数论)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1406 分析: (x+1)(x-1)是n的倍数 于是可以把n分解成n=ab,则a为(x+ ...

  5. bzoj1406: [AHOI2007]密码箱

    数学. x^2 % n = 1 则 (x+1)(x-1) = kn. 设 x+1 = k1*n1, x-1=k2*n2. 则 k1*k2=k , n1*n2=n. 算出每个大于sqrt(n)的约数,然 ...

  6. 2018.12.17 bzoj1406 : [AHOI2007]密码箱(简单数论)

    传送门 简单数论暴力题. 题目简述:要求求出所有满足x2≡1mod&ThinSpace;&ThinSpace;nx^2\equiv1 \mod nx2≡1modn且0≤x<n0\ ...

  7. 【bzoj1406】[AHOI2007]密码箱

    x2 ≡ 1 mod n => x2 = k * n + 1 => n | (x + 1) * (x - 1) 令n = a * b,则 (a | x + 1 且 b | x - 1) 或 ...

  8. 【BZOJ】【1406】【AHOI2007】密码箱

    数论 Orz iwtwiioi 果然数论很捉鸡>_>完全不知道怎么下手 $$x^2 \equiv 1 \pmod n \rightarrow (x+1)*(x-1)=k*n $$ 所以,我 ...

  9. bzoj 1406: [AHOI2007]密码箱 二次剩餘

    1406: [AHOI2007]密码箱 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 701  Solved: 396[Submit][Status] D ...

随机推荐

  1. ZooKeeper是什么

    ZooKeeper概念 相信大家对 ZooKeeper 应该不算陌生,但是你真的了解 ZooKeeper 是什么吗?如果别人/面试官让你讲讲 ZooKeeper 是什么,你能回答到哪个地步呢? 本人曾 ...

  2. [ Python ] KMP Algorithms

    def pmt(s): """ :param s: the string to get its partial match table :return: partial ...

  3. DoubleDQN---tensorflow实现

    完整代码:https://github.com/zle1992/Reinforcement_Learning_Game 开山之作: <Playing Atari with Deep Reinfo ...

  4. hashlib、hmac

    #hashlib import hashlib#md5m = hashlib.md5()m.update(b"Hello")print(m.hexdigest()) #hexdig ...

  5. bzoj1911 [Apio2010]特别行动队commando

    题目链接 斜率优化 #include<cstdio> #include<cstdlib> #include<string> #include<cstring& ...

  6. MySQL更新命令_UPDATE

    创建测试表 mysql> CREATE TABLE `product` ( -> `proID` ) NOT NULL AUTO_INCREMENT COMMENT '商品表主键', -& ...

  7. Vertical viewport was given unbounded height

    new Expanded( child: new ListView( ..... ) ); +++++++++++++++ 可以通过指定shrinkWrap = true为了你ListView. Li ...

  8. rds下载备份集在另外一台机器上恢复并应用binlog日志

    -----------------------------备份还原并启动数据库----------------------------------1.创建目录,并把下载的压缩文件拷贝到相应的目录[ro ...

  9. Windows下用python来获取微信撤回消息

    转自:https://blog.csdn.net/sunzhibin1/article/details/83348304 娱乐(windows系统) 安装itchat itchat是一个开源的pyth ...

  10. 【Git】vs code+git 不使用ssh的链接remote server的方式

    git config --global user.name "dennis wu" git config --global user.email "email" ...