Minimum divisor of a number to make the number perfect cube | C ++ program to find minimum number which divide n to make it a perfect cube ; Returns the minimum divisor ; Since 2 is only even prime , compute its power seprately . ; If count is not divisible by 3 , it must be removed by dividing n by prime number power . ; If count is not divisible by 3 , it must be removed by dividing n by prime number power . ; if n is a prime number ; Driven Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findMinNumber ( int n ) { int count = 0 , ans = 1 ; while ( n % 2 == 0 ) { count ++ ; n /= 2 ; } if ( count % 3 != 0 ) ans *= pow ( 2 , ( count % 3 ) ) ; for ( int i = 3 ; i <= sqrt ( n ) ; i += 2 ) { count = 0 ; while ( n % i == 0 ) { count ++ ; n /= i ; } if ( count % 3 != 0 ) ans *= pow ( i , ( count % 3 ) ) ; } if ( n > 2 ) ans *= n ; return ans ; } int main ( ) { int n = 128 ; cout << findMinNumber ( n ) << endl ; return 0 ; }