Sunday, 28 Nov 2021
Category: Prime Number

#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 two Geometric Progressions (a1, r1) and (a2, r2) where (x, y) represents GP with initial term x and common ratio y and an integer N, the task is to find the count of the distinct integers that belong to the first N terms of at least one of the given geometric progressions.Examples:Input: N = […]

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

Given an integer N, find a prime number S such that all digits of N occur in a contiguous sequence. There may be multiple answers. Print any one of them.Example:Input: N = 42Output: 42013Explanation: 42013 is a prime and 42 occurs as a contiguous number in it. 15427 is also a correct answer.Input: N = […]

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

2 Keys Keyboard ProblemGiven a positive integer N and a string S initially it is “A”, the task is to minimize the number of operations required to form a string consisting of N numbers of A’s by performing one of the following operations in each step:Copy all the characters present in the string S.Append all […]

#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

Number which is co-prime with all integers from a given rangeGiven two positive integers L and R, the task is to find an integer X greater than 1 such that X is co-prime with all the integers from the range [L, R].Examples:Input: L = 16, R = 17 Output: 19Explanation: Only number which is co-prime with […]

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