Giter Site home page Giter Site logo

hussaini-garba's Introduction

Tasks 3

// CPP program to find count of // primes in given array. #include <bits/stdc++.h>

using namespace std;

// Function to find count of prime

int primeCount(int arr[], int n) {

// Find maximum value in the array

int max_val = *max_element(arr, arr+n);


// USE SIEVE TO FIND ALL PRIME NUMBERS LESS

// THAN OR EQUAL TO max_val

// Create a boolean array "prime[0..n]". A

// value in prime[i] will finally be false

// if i is Not a prime, else true.

vector<bool> prime(max_val + 1, true);


// Remaining part of SIEVE

prime[0] = false;

prime[1] = false;

for (int p = 2; p * p <= max_val; p++) {


    // If prime[p] is not changed, then

    // it is a prime

    if (prime[p] == true) {


        // Update all multiples of p

        for (int i = p * 2; i <= max_val; i += p)

            prime[i] = false;

    }

}


// Find all primes in arr[]

int count = 0;

for (int i = 0; i < n; i++) 

    if (prime[arr[i]])

        count++;    


return count;

}

// Driver code

int main() {

int arr[] = { 1, 2, 3, 4, 5, 6, 7 };

int n = sizeof(arr) / sizeof(arr[0]);


cout << primeCount(arr, n);


return 0;

}

hussaini-garba's People

Contributors

hgarbalere avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.