Category: prime-factor

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

2 Keys Keyboard Problem

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

Continue Reading

Sum of all the prime divisors of a number | Set 2

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

Continue Reading

Count prime factors of N!

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

Continue Reading

Count ways to represent an integer as an exponent

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

Continue Reading