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
- Find three prime numbers with given sum
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Find the Product of first N Prime Numbers
- Find count of Almost Prime numbers from 1 to N
- Find the sum of prime numbers in the Kth array
- Find product of prime numbers between 1 to n
- Program to find sum of prime numbers between 1 to n
- Find out the prime numbers in the form of A+nB or B+nA
- Find all the prime numbers of given number of digits
- Program to find Prime Numbers Between given Interval
- Find two distinct prime numbers with given product
- 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
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.