Monday, 29 Nov 2021
Category: sieve

#include using namespace std;  const int mxn = 1e4 + 1;bool prime[mxn + 1];  void SieveOfEratosthenes(){    memset(prime, true, sizeof(prime));      for (int p = 2; p * p

Given three integers A, B, and C, the task is to find the minimum possible value of |A – X| + |B – Y| + |C – Z| such that X * Y = Z.Example:Input: A = 19, B = 28, C = 522Output: 2Explanation: The most optimal choice of X, Y, and Z for […]

#include using namespace std;  void SieveOfEratosthenes(    vector& prime, int total_sum){                    for (int i = 0; i

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 = […]

#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 = […]

#include using namespace std;  int findIndex(int arr[], int N){            int maxValue = INT_MIN;          for (int i = 0; i < N; i++) {        maxValue = max(maxValue, arr[i]);    }          map St;          for (int i = 1; i

import java.io.*;import java.lang.*;import java.util.*;public class GFG {            static boolean isPrime(int n)    {                if (n

Count prime numbers up to N that can be represented as a sum of two prime numbers Given a positive integer N, the task is to find the count of prime numbers less than or equal to N that can be represented as a sum of two prime numbers.Examples:Input: N = 6Output: 1Explanation:5 is the […]

Check if a number can be represented as a sum of a Prime Number and a Perfect SquareGiven a positive integer N, the task is to check if N can be represented as a sum of a Prime Number and a Perfect Square or not. If it is possible to represent N in required form, […]

import java.util.*; class GFG {   static int MAX = 1000000;         static void countOfPrimefactors(int[] CountDistinct)   {     boolean[]  prime = new boolean[MAX + 1];     for (int i = 0; i