Category: sieve

Count the divisors or multiples present in the Array for each element

                                        function max_element(A, N) {            let MAX = Number.MIN_VALUE;            for (let i = 0; i < A.length; i++) {                if (A[i] > MAX) {                    MAX = A[i];                }            }            return MAX;        }        function countIndex(A, N) {                        let MAX = max_element(A, A + N);                                    let freq = new Array(MAX + 1).fill(0);            for (let i = 0; i < N; i++)                freq[A[i]]++;                                    let res = new Array(MAX + 1).fill(0);            for (let i = […]

Continue Reading

Generate a sequence with product N such that for every pair of indices (i, j) and i < j, arr[j] is divisible by arr[i]

  #include using namespace std;  vector primeFactor(    int N){        vector v;          int count = 0;          while (!(N % 2)) {                  N >>= 1;        count++;    }          if (count)        v.push_back({ 2, count });          for (int i = 3;         i 2)        v.push_back({ N, 1 });      return v;}  void printAnswer(int n){            vector v        = primeFactor(n);      int maxi_size = 0, prime_factor = 0;                  for (int i = 0; i < v.size(); i++) {          if (maxi_size < v[i].second) {            maxi_size = v[i].second;            prime_factor = […]

Continue Reading