0
I need help
Why does this code not work with numbers that are the product of more than 7 numbers? For instance, insert 128 and it will be factorised successfully. But, insert 256 and it won't. This does not make sense at all to me and I spent such 2 hours today just trying to figure out what's wrong with this code. I'd love anyone to please answer me https://code.sololearn.com/cxDn6LdB0gAs/?ref=app
3 Réponses
+ 1
Are you sure you know how an array works?
: c = 1, fact[c]
Later in the code you try to access elements after index 0, that's not going to fly.
Changing the array to an initial size of 100 for example fixes the code.
If you want a resizeable array you should look into std::vector.
+ 1
Bad luck, it just appears to work for prime factors that are less than 8.
It's probably because the memory you write to just happen to not get overridden, but it could happen at any moment.
It depends on how the compiler decides on how to lay out the memory and any possible optimizations applied.
0
So why does it work for those numbers whose prime factors are less than 8?