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(Ⅱ) 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.

Sample Input

Sample Output

This is very easy because we can find that the nums of ‘1’ reflects the result.

However, it is a problem that how to calculate the result of the bits of the number.

I recommend bitset here, which is a STL lib of C++.

I will paste my code here which is easy to understand.

Notes: STL is so powerful!

2019-06-07  02:27:50  Author: WindCry1

分类: UVa模拟

0 条评论


电子邮件地址不会被公开。 必填项已用*标注