您的位置:首页 > 其它

密码箱 BZOJ - 1406

2017-10-12 15:59 323 查看
题目传送门

思路:x^2 mod n = 1

(x^2 - 1) mod n = 0

(x + 1)(x - 1) mod n = 0

我们假设n = k * n

x - 1 = k1 * n1, x + 1 = k2 * n2

k1 * k2 = k, n1 * n2 = n

我们就可以枚举所有的大于sqrt(n)的所有因子就可以

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define MAXN 100010
#define MAXE 5
#define INF 1000000000
#define MOD 10007
#define LL long long
#define ULL unsigned long long
#define pi 3.14159

using namespace std;

set<LL> Set;

int main() {
std::ios::sync_with_stdio(false);
LL n;
cin >> n;
for (LL i = 1; i * i <= n; ++i) {
if (n % i == 0) {
LL a = i, b = n / i;
for (LL j = 0; j <= n; j += b) {
if ((j - 2) % a == 0 && j - 2 >= 0) {
Set.insert(j - 1);
}
if ((j + 2) % a == 0 && j + 2 < n) {
Set.insert(j + 1);
}
}
}
}
if (Set.empty()) {
cout << "None\n";
} else {
for (set<LL>::iterator it = Set.begin(); it != Set.end(); ++it) {
cout << *it << endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: