Given a positive integer N, the task is to find the XOR of the first N prime numbers.
Input: N = 3
First 3 prime numbers are 2, 3 and 5.
And 2 ^ 3 ^ 5 = 4
Input: N = 5
- Create Sieve of Eratosthenes to identify if a number is prime or not in O(1) time.
- Run a loop starting from 1 until and unless we find N prime numbers.
- XOR all the prime numbers and neglect those which are not prime.
- Finally, print the XOR of the 1st N prime numbers.
Below is the implementation of the above approach:
- Find two prime numbers with given sum
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Find product of prime numbers between 1 to n
- Find the sum of prime numbers in the Kth array
- Find out the prime numbers in the form of A+nB or B+nA
- Find the Product of first N Prime Numbers
- Program to find sum of prime numbers between 1 to n
- Find count of Almost Prime numbers from 1 to N
- Find two distinct prime numbers with given product
- Program to find Prime Numbers Between given Interval
- Find a sequence of N prime numbers whose sum is a composite number
- Find the prime numbers which can written as sum of most consecutive primes
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
- Find the highest occurring digit in prime numbers in a range
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.