|
|
вернуться в форумWA#2 WHY? #define MAXN 1000000 #include<iostream> using namespace std; bool isprime[MAXN+1]; void create(){ memset(isprime,true,sizeof(isprime)); isprime[0]=isprime[1]=false; for (int i=2;i*i<=MAXN;++i) for (int j=i*2;j<=MAXN;j+=i) isprime[j]=false; } double Triviality(int n){ double sum; for (int i=1;i*2<=n;++i) if (n%i==0) sum+=(double)i; sum/=(double)n; return sum; } int main(void){ create(); int l,r;cin>>l>>r; if (l==1){ cout<<"1"<<endl; return 0; } for (int i=l;i<=r;++i) if (isprime[i]){ cout<<i<<endl; return 0; } double minimum=Triviality(l); int j=l; for (int i=l+1;i<=r;++i) if (minimum>Triviality(i)){ j=i; minimum=Triviality(i); } cout<<j<<endl; return 0; } Re: WA#2 WHY? I request everyone not to help you until you stop posting programs in forum! |
|
|