+ 1

How does it works?

I may not understand the condition ~-2**n%n <2. Help, please! https://code.sololearn.com/codcoa5mYJGS/?ref=app

20th Apr 2018, 10:09 AM
Paspasuy
Paspasuy - avatar
5 Respostas
+ 1
Don't worry, I don't understand it very well either. So ~-2**n inverts all's the bits in -2**n, which means that you have all ones except on the most significant nth least significant bits. then you mod n that (positive) number and take it if you have a result of 0 or 1... no idea why, however, I've just decomposed the execution steps
20th Apr 2018, 10:20 AM
Amaras A
Amaras A - avatar
+ 1
I have known something about it. Nobody don't know formula to find all prime nuns. But this works properly with small nums. You may find something like this in Wikipedia.
24th Apr 2018, 3:52 AM
Paspasuy
Paspasuy - avatar
+ 1
P.S. Sorry for my bad English.
24th Apr 2018, 3:53 AM
Paspasuy
Paspasuy - avatar
0
"~" is the Bitwise not operator it works like ~10 binary of 10 : 1010 now taking negation on all bits; 0101 every 1 becomes 0 and every 0 becomes 1 so the result is int(0101) so this is 5 as binary of 5 is 101
20th Apr 2018, 11:58 AM
RZK 022
RZK 022 - avatar
0
@Atikant hum... did ~10, got -11...
21st Apr 2018, 9:03 PM
Amaras A
Amaras A - avatar