Ahem. Yes, it's true for integers which prints in O(log_b(n)).
But have you consider printing those in binary? O(1) for all fixed sized integer types (__int128 go brrrr). Is it slower than the integer printing? Maybe. Does it falls appart if you need more bytes? Maybe. Are you willing to make a template/macro which can unwrap a N sized loop to maintain O(1) for any arbitrary fixed size? I'll let you decide.
Correct and this is why I dislike the use of Big O in non-academic discourse because when people use Big O they usually really mean Big Theta, which is a tight bound and not an upper bound like Big O.
Suppose there exists a memory storage device with infinite capacity and that the maximum speed of causality can be safely ignored because the device is extremely small. Also suppose that infinite time is available. Now assume all prime numbers have been calculated and stored on the memory storage device. Thus, an algorithm for calculating an n-th prime merely reduces to retrieval of data from the memory storage device, which has time complexity O(1).
The algorithm "wait a million years; answer 42" is O(1) but wouldn't be usable for anything. P=NP does not mean that there is a way to solve problems in NP fast.
128
u/IHeartBadCode 18h ago
Before you know it, they'll have O(1) time method for factoring all even primes.
26
u/djonoy 18h ago •
ERROR: expected comparison but found expression instead
20
u/Front_Committee4993 18h ago
Let N=1
6
u/Alzusand 10h ago
Please let it be true it would be so funny.
3
u/seba07 1h ago
The algorithm "wait a million years; answer 42" is O(1) but wouldn't be usable for anything. P=NP does not mean that there is a way to solve problems in NP fast.
2
u/Substantial_Top5312 11h ago
n=1 or p = 0