Find prime factors of Z such that Z is product of all even numbers till N that are product of two distinct prime numbers | C ++ implementation for 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void primeFactorization ( int N ) { int sieve [ N / 2 + 1 ] = { 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 ; } } } vector < int > prime ; for ( int i = 3 ; i <= N / 2 ; i ++ ) if ( sieve [ i ] == 0 ) prime . push_back ( i ) ; int x = prime . size ( ) ; cout << "2 - > " << x << endl ; for ( int i : prime ) cout << i << " - > 1" << endl ; } int main ( ) { int N = 18 ; primeFactorization ( N ) ; return 0 ; }