Can you please explain why have we taken j+=2*i in nested loop
hello @sahilkhan2312000131
becuase that j+=i will be an even number.
since i is a prime it will always be odd(except 2) .
so i*i will be odd
and
i * i + i will be even(odd + odd)
(i * i+ 2 * i) will be odd (odd + even)
so on
it can be but that will make the algo slow.
In both the images the functions are initialized with vector prototype as they are returning vector. But AFAIK, arrays and vectors are always passed by reference so there is no need for them returning the vector, they can simply take vector as argument and change the values accordingly??
And in second image we have written factors.clear(); I do not think there is any need for writing it?
vectors by default are passed as value .
yeah by default vector will be empty
So we can pass the vectors by reference like vector < int > & primes instead of returning vectors?
yeah , u can do that
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.