fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define YES cout << "YES\n";
  4. #define NO cout << "NO\n";
  5. #define opps cout<<-1<<endl;
  6. const ll con = 1e9;
  7. using namespace std;
  8. string binary(ll x) {
  9. ll temp = x;
  10. string s="";
  11. while (temp) {
  12. (temp % 2 == 0) ? s += '0' : s += '1';
  13. temp /= 2;
  14. }
  15. reverse(s.begin(), s.end());
  16. return s;
  17. }
  18. void solve(ll n) {
  19. int ones = 0 ;
  20. string x = binary(n);
  21. for (int i = 0 ; i < x.size() ; i++)
  22. x[i] == '1' ? ones++ : 0;
  23. cout<<"The parity of "<<x<<" is "<<ones<<" (mod 2)."<<endl;
  24. }
  25. int main() {
  26. ios::sync_with_stdio(0);
  27. cin.tie(0);
  28. ll n ;
  29. while (cin >> n && n != 0) {
  30. solve( n);
  31. }
  32. }
Success #stdin #stdout 0s 5328KB
stdin
Standard input is empty
stdout
Standard output is empty