【二次剩余】【bzoj 1406】: [AHOI2007]密码箱

来源:互联网 发布:手机围棋对弈软件 编辑:程序博客网 时间:2024/04/28 08:44

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


x^2=1(mod n)

(x+1)(x-1)=kn

这个时候很关键

不能说充要条件为n|x+1且n|x-1,因为这是最小公倍数

正确的方法是枚举n=a*b


#define _TEST _TEST#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <cmath>#include <algorithm>#include <map>using namespace std;/************************************************Code By willinglive    Blog:http://willinglive.cf************************************************/#define rep(i,l,r) for(int i=(l),___t=(r);i<=___t;i++)#define per(i,r,l) for(int i=(r),___t=(l);i>=___t;i--)#define MS(arr,x) memset(arr,x,sizeof(arr))#define LL long long#define INE(i,u,e) for(int i=head[u];~i;i=e[i].next)inline const int read(){int r=0,k=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')k=-1;for(;c>='0'&&c<='9';c=getchar())r=r*10+c-'0';return k*r;}/////////////////////////////////////////////////LL n,sq;map<int,bool>M;//////////////////////////////////////////////////////////////////////////////////////////////////void input(){    cin>>n;}void solve(){    sq=(LL)sqrt((double)n);    rep(i,1,sq) if(n%i==0)    {    int j=n/i;    for(int x=1;x<=n;x+=j)    {    if((x+1)%i==0) M[x]=1;    }    for(int x=j-1;x<=n;x+=j)    {    if((x-1)%i==0) M[x]=1;    }    }    for(map<int,bool>::iterator it=M.begin();it!=M.end();it++)        printf("%d\n",it->first);}/////////////////////////////////////////////////int main(){    #ifndef _TEST    freopen("std.in","r",stdin); freopen("std.out","w",stdout);    #endif    input(),solve();    return 0;}


0 0