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:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find three prime numbers with given sum
- Find two prime numbers with given sum
- Find the sum of prime numbers in the Kth array
- Program to find the LCM of two prime numbers
- Find the Product of first N Prime Numbers
- Find count of Almost Prime numbers from 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 product of prime numbers between 1 to n
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Program to find Prime Numbers Between given Interval
- C/C++ Program to find Prime Numbers between given range
- Find two distinct prime numbers with given product
- Find all the prime numbers of given number of digits
- Find the prime numbers which can written as sum of most consecutive primes
- Find a sequence of N prime numbers whose sum is a composite number
- 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
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
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.