标签:des style blog http color io os ar for
題解傳送門:http://www.cnblogs.com/htfy/archive/2012/12/11/2813448.html
這道題思路比較獨特,運用了平方差公式解二次剩餘。
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #include<cmath> #include<algorithm> #include<set> #include<map> #include<vector> #include<string> #include<queue> using namespace std; #ifdef WIN32 #define LL "%I64d" #else #define LL "%lld" #endif #define MAXN 1100 #define MAXV MAXN*2 #define MAXE MAXV*2 #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL typedef long long qword; inline int nextInt() { char ch; int x=0; bool flag=false; do ch=(char)getchar(),flag=(ch==‘-‘)?true:flag; while(ch<‘0‘||ch>‘9‘); do x=x*10+ch-‘0‘; while (ch=(char)getchar(),ch<=‘9‘ && ch>=‘0‘); return x*(flag?-1:1); } int n,m; vector<int> vec; int main() { freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int i,j,k; qword x,y,z; scanf("%d",&n); //x^2==1 (mod n) //x^2-1 == k*n //(x+1)(x-1)==k*n //n = a*b //a|(x+1) b|(x-1) qword a,b; for (a=1;a*a<=n;a++) { if (n%a!=0)continue; b=n/a; for (x=1;x<n;x+=b) if ((x+1)%a==0) vec.push_back(x); for (x=b-1;x<n;x+=b) if ((x-1)%a==0) vec.push_back(x); } sort(vec.begin(),vec.end()); vector<int>::iterator it1,it2; // it1=vec.end(); it1=unique(vec.begin(),vec.end()); for (it2=vec.begin();it2!=it1;it2++) { printf("%d\n",*it2); } return 0; }
标签:des style blog http color io os ar for
原文地址:http://www.cnblogs.com/mhy12345/p/4011914.html