Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
784 B
1
Indexable
Never
#include <stdio.h>
#include <stdlib.h>

long long int b[1000005];
long long int a[1000005];
int main()
{
    int i=0;
    int j=0;
    int n,k,N;

    int counter=0;

    scanf("%d",&n);
    N=n+1;

    while(n>0){   //還沒加1
        b[i]=n%2;
        n=n/2;
        //printf("%d",b[i]);
        i++;
    }
    //printf("%d\n",i);

    for(k=0;k<i;k++){  //找進位次數

        if (b[k]==1)
            {counter++;
            }
        else break;
    }



    while(N>0){  //加1
        a[j]=N%2;
        N=N/2;
        //printf("%d",a[j]);
        j++;
    }//printf("%d\n",j);
        //printf("**************\n");

    for(k=j-1;k>=0;k--){
        printf("%lld",a[k]);
    }
    printf(" %d",counter);


    return 0;
}