+ 4
Why this two codes give same output?
https://code.sololearn.com/cUk4t1uoGvCk/?ref=app https://code.sololearn.com/cP2zkCh720WJ/?ref=app
4 Respuestas
+ 6
If a number if divisible by 2, then that number raised to any integer exponent will be divisible by 2.
If a number is not divisible by 2, then that number raised to any integer exponent will not be divisible by 2.
So wether you're checking if that number is even, or that number raised to an exponent is even, you're checking the same thing. Example:
3 % 2 ==1; 3**2 % 2 = 1
4 % 2 == 0; 4**2 % 2 == 0
+ 4
That are pure maths
k = r [2]
Read it : k and r have the same remainder in the Euclidean division by 2
There is only two cases :
- k is even :
k = 0 [2]
<=> k ** 2 = 0**2 [2]
k ** 2 = 0 [2]
- k is odd :
k = 1 [2]
<=> k ** 2 = 1**2 [2]
k ** 2 = 1 [2]
+ 4
This has to do with math and the fact that the product of 2 numbers, whether the same or not, is even if any one, or both, are even
+ 3
The reason is because, anytime you raise a number to the power of 2 or any integer, the corresponding result will be:
1. Odd if the number u raised to the power of 2 is odd, and
2. Even if the number u raised to the power of 2 is even.
That is, for x:(x%2==1) --> (x**2)%2==1
also for x:(x%2==0) --> (x**2)%2==0
so the result from your code will exclude all odd number from the operation.