Geek and Code | Practice | GeeksforGeeks

Geek's file currently has zero lines of codes. Each morning geek can add some arbitrary lines of code(possibly zero too). Each night, each line of the code splits into two lines. Geek wants N lines of code at some moment. Find the minimum lines of code geek adds. 
Input: 
1. The first line of the input contains a single integer  T denoting the number of test cases. The description of T test cases follows.
2. The first line of each test case contains a single integer N.

Output: For each test case, print the answer

Constraints:
1. 1 <= T <= 105
2. 1 <=  N <= 109

Example:
Input:
2
14
1
Output:
3
1

Explanation:
Test Case 1: The first-morning geek can add one line of code, then in the next morning geek file will contain 2 lines of code, and then geek again can add one line of code, then in the next morning geek file will contain 6 lines of code and then geek again can add one line of code, then in the next morning geek file will contain 14. So, in the whole process geek adds 3 lines of code. 
-1
ankitparashxr3 months ago
java
Scanner sc = new Scanner(System.in);   int t = sc.nextInt();   while(t!=0)   {       int count = 0;       int n = sc.nextInt();       String str = Integer.toBinaryString(n);       for(int i =0;i<str.length();i++)       {           if(str.charAt(i)=='1')           {               count++;           }       }       System.out.println(count);       t--;
0
chessnoobdj4 months ago
Easy c++
#include<iostream>
using namespace std;

int main(){
    int t;
    cin >> t;
    while(t--){
        int n = 0;
        cin >> n;
        int cnt = 0;
        while(n&(n-1)){
            if(n%2 == 0)
                n /= 2;
            else{
                n -= 1;
                cnt += 1;
            }
        }
        cout << cnt+1 << "\n";
    }
    return 0;
}
0
amitsharmacode5 months ago
int main() {int T,N[100000],num,i,j,count;//codescanf("%d",&T);for(i=0;i<T;i++){    scanf("%d",&N[i]);}for(i=0;i<T;i++){    count=0;    num = N[i];    for(j=0;j<32;j++)    {       if((num>>j)&1)       count++;    }    printf("%d\n",count); }return 0;}
-1
c1phani1simha6 months ago
#include<iostream>#include<bits/stdc++.h>using namespace std;int main(){int t,x;cin>>t;while(t--){    cin>>x;    cout<<__builtin_popcount(x)<<endl;}return 0;}
0
Amit Singh Negi11 months ago
Amit Singh Negi
https://uploads.disquscdn.c...
0
KARAN RANSING1 year ago
KARAN RANSING
int main(){ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);int t=1;cin>>t;while(t--){ll n;cin>>n;ll ans=0;while(n!=0){    if((n&1)) ans++;    n>>=1;}cout<<ans<<"\n"; }="" }="">
0
mscodi1 year ago
mscodi
#include<stdio.h>int bin(unsigned n){    int m=0,temp=0;    while(n!=0){        temp=n%2;        if(temp==1)            m++;        n=n/2;    }    return m; }int main(){    int n, t=0,m=0;scanf("%d",&t);    while(t--){     scanf("%d",&n);    m=bin(n);     printf("%d\n",m);}}
0
codeblooded mkv1 year ago
codeblooded mkv
int main() {cin>>t;while(t--){
    int n;    cin>>n;    int count;    for(unsigned int i=0;i<n;i++) {="" i="i+1;" i="2*i;" count++;="" if(i="">n)        {cout<<count; count="0;" break;="" }="" }="" }="" return="" 0;="" }="" why="" it's="" giving="" wrong="" answers="" here="" it="" works="" fine="" on="" other="" g++="">
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.