首页 > 代码库 > Codeforces Round #276 (Div. 2)D - Maximum Value(筛法)
Codeforces Round #276 (Div. 2)D - Maximum Value(筛法)
就是一种筛法思想的应用。
#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 intconst 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(筛法)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。