Elements of Array which can be expressed as power of prime numbers | C ++ program to print all elements of Array which can be expressed as power of prime numbers ; Function to mark all the exponent of prime numbers ; If number is prime then marking all of its exponent true ; Function to display all required elements ; Function to print the required numbers ; To find the largest number ; Function call to mark all the Exponential prime nos . ; Function call ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void ModifiedSieveOfEratosthenes ( int N , bool Expo_Prime [ ] ) { bool primes [ N ] ; memset ( primes , true , sizeof ( primes ) ) ; for ( int i = 2 ; i < N ; i ++ ) { if ( primes [ i ] ) { int no = i ; while ( no <= N ) { Expo_Prime [ no ] = true ; no *= i ; } for ( int j = i * i ; j < N ; j += i ) primes [ j ] = false ; } } } void Display ( int arr [ ] , bool Expo_Prime [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) if ( Expo_Prime [ arr [ i ] ] ) cout << arr [ i ] << " ▁ " ; } void FindExpoPrime ( int arr [ ] , int n ) { int max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( max < arr [ i ] ) max = arr [ i ] ; } bool Expo_Prime [ max + 1 ] ; memset ( Expo_Prime , false , sizeof ( Expo_Prime ) ) ; ModifiedSieveOfEratosthenes ( max + 1 , Expo_Prime ) ; Display ( arr , Expo_Prime , n ) ; } int main ( ) { int arr [ ] = { 4 , 6 , 9 , 16 , 1 , 3 , 12 , 36 , 625 , 1000 } ; int n = sizeof ( arr ) / sizeof ( int ) ; FindExpoPrime ( arr , n ) ; return 0 ; }