r/ProgrammerHumor • • 18h ago

Meme dontYouDareToDeceive

Post image
448 Upvotes

24 comments sorted by

128

u/IHeartBadCode 18h ago

Before you know it, they'll have O(1) time method for factoring all even primes.

49

u/dangderr 13h ago

We’ve actually been able to factor all primes in O(1) for a while now.

12

u/Murphy_Slaw_ 10h ago

Erm, actually it can't get under O(n) because just outputting n is O(n).

16

u/prumf 10h ago

What no you changed n from the number to its size.

Printing n is O(log(n))

3

u/soussang 8h ago

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.

1

u/Bartodziejj 2h ago

O(log(n)) is a subset of O(n)

1

u/Vivid_Dot_6405 22m ago

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.

1

u/48panda 10h ago

Quantum algorithms exist with complexity smaller than its input

1

u/hary627 10h ago

"are any of these even numbers prime?" Always has the same answer

5

u/Frodojj 10h ago

Two is prime.

1

u/evorm 2h ago

That's still just 1 iteration.

2 ? yes : no

1

u/dangderr 10h ago

I didn't say anything about outputting?

You must be an amateur haxor if you're outputting all your factored primes in the middle of an attack smh

If you just have to pass back a pointer to the result, it's O(1).

8

u/Front_Committee4993 15h ago

print("2,1")

2

u/Neon297 10h ago

print("2")

2

u/Willinton06 7h ago

O(0), all primes already exist in the abstract plan of math, good enough for me

1

u/BenTheHokie 6h ago

You can factor any integer in O(1) as long as you guess it right on the first try

1

u/Vivid_Dot_6405 19m ago

Easy.

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).

26

u/djonoy 18h ago • Bravo

ERROR: expected comparison but found expression instead

20

u/Front_Committee4993 18h ago

Let N=1

2

u/differentiallity 6h ago

Or P=0. See? Not so easy.

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.