for(int i = 2; i <= int(1e6); i++){
for(int j = 0; j <= int(1e6); j += i){
//Here anything which takes O(1) time.....
} }
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
for(int i = 2; i <= int(1e6); i++){
for(int j = 0; j <= int(1e6); j += i){
//Here anything which takes O(1) time.....
} }
Название |
---|
Complexity is O(nlogn), so it will pass.
Also, you can use custom invocation to check run time.
wrong is O(1)
Notice that
j += i
. So the overall complexity is $$$O(\frac{n}{1} + \frac{n}{2} + \dots + \frac{n}{n}) = O(n \log n)$$$I dont think computer are smart enough to solve that kind of loop.
but n is constant (1e6)
So?
It is more complex then you think just a $$$O(1)$$$ and compiler can predict all 2-loops.
Some problem are even already hard to make $$$O(n \log n) \rightarrow O(n \log \log n)$$$ even if the inside function run in $$$O(1)$$$
he is trying to make joke about O(any constant) = O(1), and 10^6 log 10^6 is constant here
Ok I get the joke. And well it is also true as there is the fact that the loop $$$10^6$$$ parts are not dependent on a variable taken from the input.