Online Judge - 10931 - Parity
Online Judge - 10931 - Parity
來源代碼:UVa
前往提交 ↓
We define the parity of an integer n as the sum of the bits in binary representation computed modulo
two. As an example, the number 21=10101_2 has three 1s in its binary representation so it has parity 3(mod2), or 1.
In this problem you have to calculate the parity of an integer 1 ≤ I ≤ 2147483647.
輸入說明
Each line of the input has an integer I and the end of the input is indicated by a line where I = 0 that should not be processed.
輸出說明
For each integer I in the inputt you should print a line ‘The parity of B is P (mod 2).’, where B is the binary representation of I.
輸入輸出範例
範例 1
範例輸入
1 2 10 21 0
範例輸出
The parity of 1 is 1 (mod 2). The parity of 10 is 1 (mod 2). The parity of 1010 is 2 (mod 2). The parity of 10101 is 3 (mod 2).
範例 2
範例輸入
3 8 15 0
範例輸出
The parity of 11 is 2 (mod 2). The parity of 1000 is 1 (mod 2). The parity of 1111 is 4 (mod 2).
範例 3
範例輸入
16 31 1023 0
範例輸出
The parity of 10000 is 1 (mod 2). The parity of 11111 is 5 (mod 2). The parity of 1111111111 is 10 (mod 2).
登入後即可撰寫程式、測試範例及提交解答。
登入