`{"id":"ce54da52-07dc-440b-b7b4-95cd3c54c99b","name":"Pepcoder And Bits","description":"1. Pepcoder is feeling confident after solving many problems on Bit Manipulation.\r\n2. So, his teacher ask him to find out the count of positive integers strictly less than N, having same \r\n number of set bits as that of N.\r\n3. Let us see that if pepcoder can solve it or not. ","inputFormat":"A number N","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= N &lt;= 10^12","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n// #define ll long \n// #define long long long\nlong ncr(long n, long r){\n if(n < r){\n return 0L; \n }\n \n long res = 1L;\n \n for(long i = 0L; i < r; i++){\n res = res * (n - i);\n res = res / (i + 1);\n }\n \n return res;\n }\n\nint csb(long n){\n int res = 0;\n \n while(n > 0){\n long rsb = n & -n;\n n -= rsb;\n res++;\n }\n \n return res;\n }\n\nlong solution(long n,long k,int i)\n{\n \n}\n\nint main()\n{\n long n;cin>>n;\n \n long k=csb(n);\n long ans=solution(n,k,63);\n cout<<ans<<\"\\n\";\n return 0;\n \n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static long ncr(long n, long r){\r\n if(n < r){\r\n return 0L; \r\n }\r\n \r\n long res = 1L;\r\n \r\n for(long i = 0L; i < r; i++){\r\n res = res * (n - i);\r\n res = res / (i + 1);\r\n }\r\n \r\n return res;\r\n }\r\n \r\n public static long solution(long n, int k, int i) {\r\n \r\n }\r\n \r\n public static int csb(long n){\r\n int res = 0;\r\n \r\n while(n > 0){\r\n long rsb = n & -n;\r\n n -= rsb;\r\n res++;\r\n }\r\n \r\n return res;\r\n }\r\n \r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n long n = scn.nextLong();\r\n int k = csb(n);\r\n System.out.println(solution(n, k, 63));\r\n }\r\n\t\r\n\t\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"1024","sampleOutput":"10\r\n","questionVideo":"https://www.youtube.com/embed/DMTw6pP5zTg?end=72","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f3e3dbef-d2b7-4f6d-b357-2ef3738e6c91","name":"Bit Manipulation For Intermediate","slug":"bit-manipulation-for-intermediate-9995","type":0},{"id":"63acf499-ee0c-408e-8dfc-c374d998960d","name":"Pepcoder And Bits","slug":"pepcoder-and-bits","type":1}],"next":{"id":"6bb0f5c3-9cc3-44b7-abeb-399bf578ad6e","name":"Pepcoder and Bits MCQ","type":0,"slug":"pepcoder-and-bits-mcq"},"prev":{"id":"e2f30145-f313-487c-ac28-8d49e0263c0a","name":"Reduce N to 1","type":3,"slug":"reduce-n-to-1"}}}`

# Pepcoder And Bits

1. Pepcoder is feeling confident after solving many problems on Bit Manipulation. 2. So, his teacher ask him to find out the count of positive integers strictly less than N, having same number of set bits as that of N. 3. Let us see that if pepcoder can solve it or not.

`{"id":"ce54da52-07dc-440b-b7b4-95cd3c54c99b","name":"Pepcoder And Bits","description":"1. Pepcoder is feeling confident after solving many problems on Bit Manipulation.\r\n2. So, his teacher ask him to find out the count of positive integers strictly less than N, having same \r\n number of set bits as that of N.\r\n3. Let us see that if pepcoder can solve it or not. ","inputFormat":"A number N","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= N &lt;= 10^12","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n// #define ll long \n// #define long long long\nlong ncr(long n, long r){\n if(n < r){\n return 0L; \n }\n \n long res = 1L;\n \n for(long i = 0L; i < r; i++){\n res = res * (n - i);\n res = res / (i + 1);\n }\n \n return res;\n }\n\nint csb(long n){\n int res = 0;\n \n while(n > 0){\n long rsb = n & -n;\n n -= rsb;\n res++;\n }\n \n return res;\n }\n\nlong solution(long n,long k,int i)\n{\n \n}\n\nint main()\n{\n long n;cin>>n;\n \n long k=csb(n);\n long ans=solution(n,k,63);\n cout<<ans<<\"\\n\";\n return 0;\n \n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static long ncr(long n, long r){\r\n if(n < r){\r\n return 0L; \r\n }\r\n \r\n long res = 1L;\r\n \r\n for(long i = 0L; i < r; i++){\r\n res = res * (n - i);\r\n res = res / (i + 1);\r\n }\r\n \r\n return res;\r\n }\r\n \r\n public static long solution(long n, int k, int i) {\r\n \r\n }\r\n \r\n public static int csb(long n){\r\n int res = 0;\r\n \r\n while(n > 0){\r\n long rsb = n & -n;\r\n n -= rsb;\r\n res++;\r\n }\r\n \r\n return res;\r\n }\r\n \r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n long n = scn.nextLong();\r\n int k = csb(n);\r\n System.out.println(solution(n, k, 63));\r\n }\r\n\t\r\n\t\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"1024","sampleOutput":"10\r\n","questionVideo":"https://www.youtube.com/embed/DMTw6pP5zTg?end=72","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f3e3dbef-d2b7-4f6d-b357-2ef3738e6c91","name":"Bit Manipulation For Intermediate","slug":"bit-manipulation-for-intermediate-9995","type":0},{"id":"63acf499-ee0c-408e-8dfc-c374d998960d","name":"Pepcoder And Bits","slug":"pepcoder-and-bits","type":1}],"next":{"id":"6bb0f5c3-9cc3-44b7-abeb-399bf578ad6e","name":"Pepcoder and Bits MCQ","type":0,"slug":"pepcoder-and-bits-mcq"},"prev":{"id":"e2f30145-f313-487c-ac28-8d49e0263c0a","name":"Reduce N to 1","type":3,"slug":"reduce-n-to-1"}}}`

Editor

# Pepcoder And Bits

easy

1. Pepcoder is feeling confident after solving many problems on Bit Manipulation. 2. So, his teacher ask him to find out the count of positive integers strictly less than N, having same number of set bits as that of N. 3. Let us see that if pepcoder can solve it or not.

1 <= N <= 10^12

## Format

A number N

### Output

Check the sample ouput and question video.

## Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}1024`

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}10 ```

Question Video

Discussions

Show Discussion

Related Resources