密码箱 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)的所有因子就可以
思路: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; }
相关文章推荐
- [BZOJ1406][AHOI2007]密码箱(数论)
- [bzoj1406][数论]密码箱
- bzoj 1406: [AHOI2007]密码箱 数学
- 【bzoj1406】【AHOI2007】【密码箱】【数论】
- 【BZOJ】【1406】【AHOI2007】密码箱
- 【BZOJ-1406】密码箱 约数 + 乱搞 + set?
- BZOJ 1406 [AHOI2007]密码箱 数论
- BZOJ 1406 AHOI2007 密码箱 数论
- BZOJ系列1406《[AHOI2007]密码箱》题解
- BZOJ 1406 密码箱
- BZOJ1406[AHOI2007密码箱]
- BZOJ 1406 密码箱
- BZOJ1406 密码箱
- BZOJ1406 [AHOI2007] 密码箱
- bzoj 1406: [AHOI2007]密码箱
- [bzoj1406]密码箱 解题报告
- 【BZOJ 1406】 [AHOI2007]密码箱
- BZOJ1406: [AHOI2007]密码箱
- [BZOJ1406][AHOI2007]密码箱(数学相关)
- 【BZOJ】1406: [AHOI2007]密码箱