Sunday, 28 Nov 2021
Category: prime-factor

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

Sum of all the prime divisors of a number | Set 2 Given a number N, the task is to find the sum of all the prime factors of N. Examples:Input: 10Output: 7Explanation: 2, 5 are prime divisors of 10Input: 20Output: 7Explanation: 2, 5 are prime divisors of 20Approach: This problem can be solved by finding […]

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

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

Count prime factors of N! Given an integer N, the task is to count the number of prime factors of N!. Examples: Input: N = 5Output: 3Explanation: Factorial of 5 = 120. Prime factors of 120 are {2, 3, 5}. Therefore, the count is 3. Input: N = 1Output: 0 Naive Approach: Follow the steps […]

#include using namespace std;    long long int gcd(long long int a,                   long long int b) {          while (b > 0) {            long long int rem = a % b;         a = b;         b = rem;     }             return a; }    int countNumberOfWays(long long int n) {          if (n == […]