Sort by

recency

|

38 Discussions

|

  • + 0 comments

    include

    include

    using namespace std; long long int cntvalue(long long int n) { long long int u=0; while(n) { if((n&1)==0) u++; n=n>>1; } return 1<>n; cout<

  • + 0 comments

    100% works. C++ solution.

    include

    include

    using namespace std;

    long solve(long n) { long k,count = 0; while(n!=0) {

        k=n%2;
    
        if(k==0)
        count++;
    
    
        n=n/2;
    
    }
    long result = pow(2,count);
    return result;
    

    }

    int main() { long n; cin >> n; long result = solve(n); cout << result << endl; return 0; }

  • + 0 comments

    public static void main(String[] args) { Scanner in = new Scanner(System.in); long n = in.nextLong(); int s=0; for(int i=0;i

            if(a==k){
             s++;
    
            }
    
        }
        System.out.println(s); 
    }
    
  • + 0 comments

    My Below code is failing for some test case kindly help me where i did mistake.

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
    
        long n = in.nextLong();
    
        System.out.println(LongStream.range(0, n).filter(num -> ((n+num) == (n^num))).count());
    
    }
    
  • + 0 comments

    My O(1) Solution

    #include <stdio.h>
    
    int main(void) {
        // a+b = xor(a,b) iff a&b == 0
        long n, res;
        scanf("%li", &n);
        if (!n) {
            puts("1");
        } else if ((n & (n-1)) == 0) {
            printf("%li\n", n);
        } else {
            __asm__ volatile ("popcnt %%rcx, %%rax" :: "c"(n));
            __asm__ volatile ("bsr %rcx, %rcx\n"
                              "inc %rcx\n"
                              "subq %rax, %rcx\n"
                              "movq $1, %r8\n"
                              "shlq %cl, %r8\n");
            __asm__ volatile ("movq %%r8, %0" : "=r"(res));
            printf("%li\n", res);
        }
        return 0;
    }