什么神奇的数论题。。。

x2 ≡ 1 (mod n)      =>

x2 = k * n + 1        =>

n | (x + 1) * (x - 1)

 

令n = a * b,则

(a | x + 1 且 b | x - 1) 或 (a| x - 1 且 b | x + 1)

于是暴力枚举a ∈ [1, sqrt(n)] 就好了

我比较懒,直接存到set里去了

 

 1 /**************************************************************
 2     Problem: 1406
 3     User: rausen
 4     Language: C++
 5     Result: Accepted
 6     Time:36 ms
 7     Memory:808 kb
 8 ****************************************************************/
 9  
10 #include <cstdio>
11 #include <set>
12  
13 using namespace std;
14 typedef long long ll;
15 typedef set <ll> :: iterator ITER;
16  
17 set <ll> S;
18 ll n;
19  
20 int main() {
21   int i, k;
22   ll a, b, x;
23   scanf("%lld\n", &n);
24   for (i = 1; i * i <= n; ++i)
25     if (n % i == 0) {
26       a = i, b = n / i;
27       for (k = 0; (x = b * k + 1) < n; ++k)
28     if ((x + 1) % a == 0)
29       S.insert(x);
30       for (k = 1; (x = b * k - 1) < n; ++k)
31     if ((x - 1) % a == 0)
32       S.insert(x);
33     }
34   for (ITER it = S.begin(); it != S.end(); ++it)
35     printf("%lld\n", *it);
36   return 0;
37 }
View Code

 

posted on 2015-02-16 17:39  Xs酱~  阅读(439)  评论(0编辑  收藏  举报