eolymp
bolt
Try our new interface for solving problems
Problems

Fermat`s Christmas Theorem

Fermat`s Christmas Theorem

In a letter dated December 25, 1640; the great mathematician Pierre de Fermat wrote to Marin Mersenne that he just proved that an odd prime \textbf{p} is expressible as \textbf{p = a^2 + b^2} if and only if \textbf{p} is expressible as \textbf{p = 4c + 1}. As usual, Fermat didn’t include the proof, and as far as we know, never wrote it down. It wasn’t until 100 years later that no one other than Euler proved this theorem. To illustrate, each of the following primes can be expressed as the sum of two squares: \textbf{5 = 2^2 + 1^2 13 = 3^2 + 2^2 17 = 4^2 + 1^2 41 = 5^2 + 4^2} Whereas the primes \textbf{11}, \textbf{19}, \textbf{23}, and \textbf{31} cannot be expressed as a sum of two squares. Write a program to count the number of primes that can be expressed as sum of squares within a given interval. \InputFile Your program will be tested on one or more test cases. Each test case is specified on a separate input line that specifies two integers \textbf{L}, \textbf{U} where \textbf{L} ≤ \textbf{U} < \textbf{1000000}. The last line of the input file includes a dummy test case with both \textbf{L = U = −1}. \OutputFile For each test case, write the result using the following format: \textbf{L U x y} where \textbf{L} and \textbf{U} are as specified in the input. \textbf{x} is the total number of primes within the interval \[\textbf{L}, \textbf{U}\] (inclusive), and \textbf{y} is the total number of primes (also within \[\textbf{L}, \textbf{U}\]) that can be expressed as a sum of squares.
Time limit 1 second
Memory limit 64 MiB
Input example #1
10 20
11 19
100 1000
-1 -1
Output example #1
10 20 4 2
11 19 4 2
100 1000 143 69