Find maximum operations to reduce N to 1 | Java program to find maximum number moves possible ; To store number of prime factors of each number ; Function to find number of prime factors of each number ; if i is a prime number ; increase value by one from it 's preveious multiple ; make prefix sum this will be helpful for multiple test cases ; Driver Code ; Generate primeFactors array ; required answer
import java . io . * ; class GFG { static int N = 1000005 ; static int primeFactors [ ] = new int [ N ] ; static void findPrimeFactors ( ) { for ( int i = 2 ; i < N ; i ++ ) if ( primeFactors [ i ] == 0 ) for ( int j = i ; j < N ; j += i ) primeFactors [ j ] = primeFactors [ j / i ] + 1 ; for ( int i = 1 ; i < N ; i ++ ) primeFactors [ i ] += primeFactors [ i - 1 ] ; } public static void main ( String [ ] args ) { findPrimeFactors ( ) ; int a = 6 , b = 3 ; System . out . println ( primeFactors [ a ] - primeFactors [ b ] ) ; } }