ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1118. Nontrivial Numbers

WA#2 WHY?
Posted by snowfly 7 Aug 2009 16:18
#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?
Posted by Al.Cash 7 Aug 2009 17:07
I request everyone not to help you until you stop posting programs in forum!