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

Why wa 11??
Posted by wiwi 19 Nov 2020 04:28
----
ll l,r;
    cin >> l >> r;
    if(l==1){
        cout << 1;
        return 0;
    }
    if(l == r){
        cout << l;
        return 0;
    }
    ll n = 1e6+2;
    vector<bool> prime(n+1,1);
    prime[0]=prime[1] = 0;
    for( ll i =2; i*i <= n; i++)
    {
        if(prime[i])
        {
            for(ll j = i*i; j <= n; j+=i)
                prime[j]=0;
        }
    }

    for(ll i = r; i >= l; i--){
        if(prime[i])
        {

            cout << i;
            return 0;
        }
    }
    double mx =1e11;
    ll ans = 0;
    for(ll i = r; i >= l; i--){

        if(i % 2 == 0)
            continue;


        double suma = 1;
        for(ll k = 2; k*k <= i; k++){

            if( i % k == 0 ){
                suma += k;
                if(i/k != k){

                    suma += (i/k);
                }
            }
        }

        double q=(suma)/(i);


        if( q < mx){
            mx = q;
            ans = i;
        }

    }
    cout << ans;
    return 0;
----

I used the sieve of Eratosthenes to find prime numbers. If I have not found prime numbers on the interval [l; r], then I iterate over all numbers with [l; r]. I go through the divisors (sqrt (i)). I calculate the minimum. What's wrong? WA 11. Google translator, sorry.