Question:
A lucky number is found by listing all numbers up to n. 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32 And then remove every second number so we get: 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 Now the next numbers after 1 here is 3 so now remove every third number: 1,3,7,9,13,15,19,21,25,27,29 Now the next number after 3 is 7, so now remove every seventh number: 1,3,7,9,13,15,21,25,27,29 And the next number after 7 in our list is 9 so now remove every ninth number. etcThe remaining numbers are lucky numbers: 1,3,7,9,13,15,21,25,31
Hello, I am a relatively new Python programmer who is trying to figure this out. I did not even come close to solving this, and I want them up to the 100 billions so an advice of the best way to go about this is welcome. here is my best try to get this done in Numpy:
Answer:
IIUC, one way usingwhile
loop with checker:If you have better answer, please add a comment about this, thank you!