首页 > 代码库 > Codeforces Round #276 div1 B. Maximum Value Hash 乱搞

Codeforces Round #276 div1 B. Maximum Value Hash 乱搞

#include <cstdio>#include <cmath>#include <cstring>#include <ctime>#include <iostream>#include <algorithm>#include <set>#include <vector>#include <sstream>#include <queue>#include <typeinfo>#include <fstream>typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)//输入输出挂const int maxn=2000000+100;int a[maxn];int main(){    sspeed;    int n;    cin>>n;    int x;    for(int i=0;i<n;i++)    {        cin>>x;        a[x]=x;    }    for(int i=0;i<maxn;i++)    {        if(a[i]!=i)            a[i]=a[i-1];    }//hash一下    int ans=0;    for(int i=2;i<maxn;i++)    {        if(a[i]==i)        {            for(int j=i+i-1;j<maxn;j+=i)            {                if(a[j]%i>ans&&a[j]>i)                    ans=a[j]%i;            }        }    }//每次从离Mod最大的地方开始寻找    cout<<ans<<endl;    return 0;}

 

Codeforces Round #276 div1 B. Maximum Value Hash 乱搞