Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C++ program to generate all prime numbers
- // less than N in O(N)
- #include<bits/stdc++.h>
- #include <iostream>
- #include <stdio.h>
- #include <set>
- using namespace std;
- static int NumUnos(int n) {
- int cont = 0;
- while(n > 0) {
- int dig = n % 2;
- if(dig == 1) {
- cont++;
- }
- n /= 2;
- }
- return cont;
- }
- int countPrimeSetBits(int L, int R) {
- // Write your code here
- int primos[] ={ 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
- int size = sizeof(primos) / sizeof(int);
- set<int> hash;
- for(int i =0; i<size; i++) {
- hash.insert(primos[i]);
- }
- int cont = 0;
- for(int i = L; i<= R; i++) {
- int unos = NumUnos(i);
- if( hash.find(unos) != hash.end()) {
- cont ++;
- }
- }
- return cont;
- }
- // driver program to test above function
- int main()
- {
- /*
- int N = 13 ; // Must be less than MAX_SIZE
- manipulated_seive(N);
- // pint all prime number less then N
- for (int i=0; i<prime.size() && prime[i] <= N ; i++)
- cout << prime[i] << " ";
- */
- //int L = 6, R = 10;
- int L = 10, R = 15;
- //int L =
- cout << countPrimeSetBits( L, R) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement