Saturday, November 16, 2024
HomeSoftware DevelopmentRely of integers in vary which aren't divisible by first Ok...

Rely of integers in vary [L, R] which aren’t divisible by first Ok Prime numbers

[ad_1]

#embrace <bits/stdc++.h>

utilizing namespace std;

  

void SieveOfEratosthenes(int n,

                         vector<int>& v, int ok)

{

    bool prime[n + 1];

    memset(prime, true, sizeof(prime));

  

    for (int i = 2; i * i <= n; i++) {

        if (prime[i]) {

            for (int j = i * i; j <= n;

                 j += i)

                prime[j] = false;

        }

    }

  

    

    

    for (int i = 2; i < n; i++) {

        if (prime[i]) {

            v.push_back(i);

        }

        if (v.dimension() == ok) {

            break;

        }

    }

}

  

int total_count(int L, int R, int ok)

{

    vector<int> v;

  

    

    SieveOfEratosthenes(100000, v, ok);

  

    

    int arr[R + 1] = { 0 };

  

    

    

    

    for (int i = 0; i < v.dimension(); i++) {

  

        

        

        

        int val;

  

        if (L % v[i] == 0) {

            val = L;

        }

        else {

            val = ((L / v[i]) + 1) * v[i];

        }

        for (int j = val; j <= R; j = j

                                      + v[i]) {

            arr[j] = 1;

        }

    }

  

    int rely = 0;

    for (int i = L; i <= R; i++) {

        if (arr[i] == 0) {

            rely++;

        }

    }

  

    return rely;

}

  

int fundamental()

{

    int L = 10, R = 25;

    int Ok = 3;

  

    

    cout << total_count(L, R, Ok);

    return 0;

}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments