|
|
back to boardWhy 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. |
|
|