Find prime factors of Z such that Z is product of all even numbers till N that are product of two distinct prime numbers | Java implementation of the above approach ; Function to print the prime factorization of the product of all numbers <= N that are even and can be expressed as a product of two distinct prime numbers ; Sieve of Eratosthenese ; Store prime numbers in the range [ 3 , N / 2 ] ; Print the coefficient of 2 in the prime factorization ; Print the coefficients of other primes ; Driver Code ; Input ; Function calling
import java . util . * ; import java . util . HashMap ; class GFG { static void primeFactorization ( int N ) { int [ ] sieve = new int [ N / 2 + 1 ] ; for ( int i = 0 ; i <= N / 2 ; i ++ ) { sieve [ i ] = 0 ; } for ( int i = 2 ; i <= N / 2 ; i ++ ) { if ( sieve [ i ] == 0 ) { for ( int j = i * i ; j <= N / 2 ; j += i ) { sieve [ j ] = 1 ; } } } ArrayList < Integer > prime = new ArrayList < Integer > ( ) ; for ( int i = 3 ; i <= N / 2 ; i ++ ) if ( sieve [ i ] == 0 ) prime . add ( i ) ; int x = prime . size ( ) ; System . out . println ( "2 - > " + x ) ; for ( int i : prime ) System . out . println ( i + " - > 1" ) ; } public static void main ( String args [ ] ) { int N = 18 ; primeFactorization ( N ) ; } }