Algorithm of 406 - Prime Cuts

Problem Description Link
Algorithm:

This is a prime related problem . In this problem you need to   generate the  prime number from 1 to N.
Where 1 also a prime number in this problem .
After generate the all prime number from 1 to N count the prime numbers check.
 I f prime numbers are even then print the center (c*2) primes  .
I f prime numbers are odd then print the center (c*2-1) primes  .
If center (c*2) for even or (c*2-1) for odd excite the list of all prime numbers then print all prime from 1 to N
For example.
Input: N=21  C= 2
Prime numbers are : 1, 2, 3, 5, 7, 11, 13, 17, 19
Total 9 primes  it is odd so print middle  (c*2-1)=(2*2-1)=3  primes.
1, 2, 3, 5, 7, 11, 13, 17, 19
Input: N=18  C= 2
Prime numbers are : 1, 2, 3, 5, 7, 11, 13, 17
Total 8 primes  it is even so print middle  (c*2)=(2*2)=4 primes.
1, 2, 3, 5, 7, 11, 13, 17



image

No comments:

Post a Comment

Write your comment - Share Knowledge and Experience