Toph Problem Tidy Bits Solution

Problem Link

Toph Problem Tidy Bits Solution

#include<bits/stdc++.h>
using namespace std;
int calculate_one(int n)
{
    int cont=0;
    while(n!=0)
    {
        if(n%2==1)  //count 1
            cont++;
        n=n/2;
    }
    return cont;
}
int main()
{
    int n;
    cin>>n;
    int one=calculate_one(n);
    int i=0;
    while(1)
    {
        if(calculate_one(i)==one) //checking 
        {
            cout<<i<<endl;
            break;
        }
        i++;
    }
    return 0;
}

No comments

Theme images by enjoynz. Powered by Blogger.