Fermat's Christmas Theorem
Time limit1sMemory limit128 MB
For each query interval, count the primes in it and how many of those satisfy the sum-of-two-squares criterion.
- Level
Medium4 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
On December 25, 1640, the great mathematician Pierre de Fermat sent Marin Mersenne a letter containing the following claim.
I have just proved that an odd prime can be written as if and only if can be written as .
The letter contained no proof; Euler proved it 100 years later. Indeed, can each be written as a sum of two squares.
By contrast, cannot be written as a sum of two squares.
Here the two squares are squares of non-negative integers, and the prime also counts as a sum of two squares.
Given an interval , write a program that counts how many primes in the interval can be written as a sum of two squares.
Input
The input consists of several test cases. Each test case is a single line containing two integers and separated by a space. ()
In the last line, and are both equal to ; this line is not processed.
Output
For each test case, print four integers , , , on one line, separated by spaces. and are the given input values, is the number of primes in the interval , and is the number of those primes that can be written as a sum of two squares.