Min operations to reduce N by multiplying by any number or taking square root | C ++ program for above approach ; Function to reduce N to its minimum possible value by the given operations ; Keep replacing n until is an integer ; Keep replacing n until n is divisible by i * i ; Print the answer ; Driver Code ; Given N ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void minValue ( int n ) { while ( int ( sqrt ( n ) ) == sqrt ( n ) && n > 1 ) { n = sqrt ( n ) ; } for ( int i = sqrt ( n ) ; i > 1 ; i -- ) { while ( n % ( i * i ) == 0 ) n /= i ; } cout << n ; } int main ( ) { int N = 20 ; minValue ( N ) ; }