标签:
5
4
6
9
10
13
8
分析:i%k=j%k(i>j)
即(i-j)%k=0;
当仅当k是i-j的因子,所以处理出任意两数的差之后筛一下就好了;
代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <climits> #include <cstring> #include <string> #include <set> #include <map> #include <queue> #include <stack> #include <vector> #include <list> #define rep(i,m,n) for(i=m;i<=n;i++) #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++) #define mod 1000000007 #define inf 0x3f3f3f3f #define pb push_back #define mp make_pair #define fi first #define se second #define pii pair<int,int> #define ll long long #define pi acos(-1.0) const int maxn=1e6+10; const int dis[4][2]={{0,1},{-1,0},{0,-1},{1,0}}; using namespace std; ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} ll qpow(ll p,ll q,ll mo){ll f=1;while(q){if(q&1)f=f*p%mo;p=p*p%mo;q>>=1;}return f;} int n,m,k,t,a[maxn],b[maxn]; int main() { int i,j; scanf("%d",&n); rep(i,0,n-1)scanf("%d",&a[i]); sort(a,a+n); rep(i,0,n-1)rep(j,i+1,n-1)b[a[j]-a[i]]=1; rep(i,1,a[n-1]) { bool flag=true; int p=i; while(p<=a[n-1]) { if(b[p]){flag=false;break;} else p+=i; } if(flag)break; } printf("%d\n",i); //system ("pause"); return 0; }
标签:
原文地址:http://www.cnblogs.com/dyzll/p/5751524.html