Given an integer N, below operations can be performed any number of times on N:
- Multiply N by any positive integer X i.e. N = N * X.
- Replace N with square root of N (N must be an integer) i.e. N = sqrt(N).
The task is to find the minimum integer to which N can be reduced with the above operations.
Input: N = 20
We can multiply 20 by 5, then take sqrt(20*5) = 10, this is the minimum number that 20 can be reduced to with the given operations.
Input: N = 36
Take sqrt(36). Number 6 can’t be reduced further.
- First factorize the number N.
- Say, 12 has factors 2, 2 and 5. Only the factors that are repeating can be reduced with sqrt(n) i.e. sqrt(2*2) = 2.
- The numbers appearing only once in the factors cannot be further reduced.
- So, the final answer will be the product of all the distinct prime factors of number N
Below is the implementation of the above approach:
- Print matrix after applying increment operations in M ranges
- Sort an array after applying the given equation
- Minimize the absolute difference of sum of two subsets
- Minimize the sum of the squares of the sum of elements of each group the array is divided into
- Minimize the maximum minimum difference after one removal from array
- Minimize the difference between the maximum and minimum values of the modified array
- Minimize the number of replacements to get a string with same number of 'a', 'b' and 'c' in it
- Operations on Sparse Matrices
- Find maximum operations to reduce N to 1
- Euclid's Algorithm when % and / operations are costly
- Implement *, - and / operations using only + arithmetic operator
- Minimum gcd operations to make all array elements one
- Online Queries for GCD of array after divide operations
- Maximum Possible Product in Array after performing given Operations
- Count operations of the given type required to reduce N to 0