Special prime numbers | C # program to check whether there exist at least k or not in range [ 2. . n ] ; Generating all the prime numbers from 2 to n . ; If a prime number is Special prime number , then we increments the value of k . ; If at least k Special prime numbers are present , then we return 1. else we return 0 from outside of the outer loop . ; Driver function
using System ; using System . Collections ; class GFG { static ArrayList primes = new ArrayList ( ) ; static void SieveofEratosthenes ( int n ) { bool [ ] visited = new bool [ n * n + 2 ] ; for ( int i = 2 ; i <= n + 1 ; i ++ ) if ( ! visited [ i ] ) { for ( int j = i * i ; j <= n + 1 ; j += i ) visited [ j ] = true ; primes . Add ( i ) ; } } static bool specialPrimeNumbers ( int n , int k ) { SieveofEratosthenes ( n ) ; int count = 0 ; for ( int i = 0 ; i < primes . Count ; i ++ ) { for ( int j = 0 ; j < i - 1 ; j ++ ) { if ( ( int ) primes [ j ] + ( int ) primes [ j + 1 ] + 1 == ( int ) primes [ i ] ) { count ++ ; break ; } } if ( count == k ) return true ; } return false ; } public static void Main ( ) { int n = 27 , k = 2 ; if ( specialPrimeNumbers ( n , k ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }