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
using System ; class GFG { static void ModifiedSieveOfEratosthenes ( int N , bool [ ] Expo_Prime ) { bool [ ] primes = new bool [ N ] ; for ( int i = 0 ; i < N ; i ++ ) primes [ i ] = true ; 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 ; } } } static void Display ( int [ ] arr , bool [ ] Expo_Prime , int n ) { for ( int i = 0 ; i < n ; i ++ ) if ( Expo_Prime [ arr [ i ] ] ) Console . Write ( arr [ i ] + " ▁ " ) ; } static 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 = new bool [ max + 1 ] ; ModifiedSieveOfEratosthenes ( max + 1 , Expo_Prime ) ; Display ( arr , Expo_Prime , n ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 6 , 9 , 16 , 1 , 3 , 12 , 36 , 625 , 1000 } ; int n = arr . Length ; FindExpoPrime ( arr , n ) ; } }