【BZOJ】1406: [AHOI2007]密码箱

http://www.lydsy.com/JudgeOnline/problem.php?id=1406

题意:求$0<=x<n, 1<=n<=2,000,000,000, 且x^2 \equiv 1 \pmod{n}$的所有$x$

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
set<ll> s;
int main() {
	ll n; scanf("%lld", &n);
	for(int i=1; i*i<=n; ++i) if(n%i==0) {
		ll a=i, b=n/i, x;
		for(int k=0; b*k+1<n ; ++k) {
			x=b*k+1; if((x+1)%a==0) s.insert(x);
		}
		for(int k=1; b*k-1<n; ++k) {
			x=b*k-1; if((x-1)%a==0) s.insert(x);
		}
	}
	for(set<ll>::iterator it=s.begin(); it!=s.end(); ++it)
		printf("%lld\n", *it);
	return 0;
}

  


 

好神的题= =

首先化简容易得到$(x+1)(x-1) = kn$,于是就翻题解了= =,神题不解释= =

于是得到$n | (x+1)(x-1)$

设$n=ab$,那么由 $ ab | (x+1)(x-1) \Rightarrow \left( a|(x+1) \land b|(x-1) \right) \lor \left( a|(x-1) \land b|(x+1) \right) $

我发现我无法证明其充分性怎么办QAQ

于是$O(\sqrt{n}ln \sqrt{n})$就能搞定啦= =

posted @ 2015-02-06 17:16  iwtwiioi  阅读(289)  评论(0编辑  收藏  举报