BZOJ 1406 数论

思路:

$x^2=kn+1$

$x^2-1=kn$

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

令$x+1=k1n1$,$x-1=k2n2$,其中$k1k2=k$,$n1n2=n$

枚举n约数 >=$\sqrt{n}$的,代入验证

去重

//By SiriusRen
#include <set>
#include <cstdio>
using namespace std;
#define int long long
int n;set<int>s;
signed main(){
    scanf("%lld",&n);
    if(!n){puts("None");return 0;}
    for(int i=1;i*i<=n;i++)if(n%i==0){
        int res=n/i;
        for(int j=1;j<=n;j+=res)if((j+1)%i==0)s.insert(j);
        for(int j=res-1;j<=n;j+=res)if((j-1)%i==0)s.insert(j);
    }for(set<int>::iterator it=s.begin();it!=s.end();++it)printf("%d\n",*it);
}

 

posted @ 2017-03-21 08:19  SiriusRen  阅读(112)  评论(0编辑  收藏  举报