标签:style blog io color os sp for div on
就是一种筛法思想的应用。
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<set> #include<vector> #include<algorithm> #include<stack> #include<queue> #include<cctype> #include<sstream> using namespace std; #define pii pair<int,int> #define LL long long int const int eps=1e-8; const int INF=1000000000; const int maxn=200009; int n,a[maxn],ans=-1; int main() { //freopen("in9.txt","r",stdin); //freopen("out.txt","w",stdout); scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i]); } if(n==1){printf("0\n");return 0;} sort(a,a+n); for(int i=0;i<n-1;i++) { if(i&&a[i]==a[i-1]) continue; for(int t=a[i]*2;t<=a[n-1];t+=a[i]) { int p=lower_bound(a,a+n,t)-a; ans=max(ans,a[p-1]%a[i]); } ans=max(ans,a[n-1]%a[i]); } printf("%d\n",ans); //fclose(stdin); //fclose(stdout); return 0; }
Codeforces Round #276 (Div. 2)D - Maximum Value(筛法)
标签:style blog io color os sp for div on
原文地址:http://www.cnblogs.com/zywscq/p/4080239.html