标签:
Description
Input
Output
Sample Input
12
Sample Output
1 5 7 11
Analyse:
x^2=k*n+1 -> x^2-1=kn
(x-1)(x+1)=kn-> (x-1)(x+1)=(k1*n1)*(k2*n2); && k1*k2==k; n1*n2==n;
CODE:
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<string> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #define INF 0x7fffffff #define SUP 0x80000000 #define mem(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long LL; const int N=100007; int main() { LL n; while(scanf("%lld",&n)==1) { LL b; set<LL> ans; for(LL i=1;i*i<=n;i++){ if(n%i) continue; b=n/i; for(LL j=1;j<n;j+=b){ if((j+1)%i==0) ans.insert(j); } for(LL j=b-1;j<n;j+=b){ if((j-1)%i==0) ans.insert(j); } } set<LL>::iterator it; if(!ans.size()) printf("None\n"); else{ for(it=ans.begin();it!=ans.end();it++) printf("%lld\n",*it); } } return 0; }
标签:
原文地址:http://blog.csdn.net/code_or_code/article/details/44832033