Fermat's Chirstmas Theorem
Time limit:1000 ms
Memory limit:65536kb
64bit Io format:% LLD & % llusubmit status practice sdutoj 2093
Description
In a letter dated December 25,164 0; the great mathematician pierre de Fermat wrote to Marin Mersenne that he just proved that an odd prime p is expressible as P = a2 + B2 if and only if p is expressible as P = 4c + 1. as usual, Fermat didn't include the proof, and as far as we know, neverwrote it down. it wasn't until 100 years later that no one other than Euler proved this theorem.
Input
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 l, u where L ≤ U <1,000,000 the last line of the input file into des a dummy test case with both L = u = −1.
Output
L u x ywhere L and u are as specified in the input. X is the total number of Primes within the interval [L, u] (random Sive,) and Y is the total number of Primes (also within [L, u]) that can be expressed as a sum of squares.
Sample Input
10 2011 19100 1000-1 -1
Sample output
10 20 4 211 19 4 2100 1000 143 69
# Include <stdio. h> # include <string. h> # define n 1000005int prime [100005]; int flag [1000005]; int e; void getp () // prime number table to find the prime number Storage stack {int I, J; E = 0; memset (flag, 0, sizeof (FLAG); // tag initialization for (I = 2; I <n; I ++) {If (flag [I] = 0) {Prime [E ++] = I; // stack entry} For (j = 0; j <E & I * prime [J] <n; j ++) {flag [I * prime [J] = 1 ;}} int main () {int L, U, X, Y; getp (); int I; while (scanf ("% d", & L, & U )) {If (L =-1 & U =-1) break; X = 0; y = 0; for (I = 0; I <E; I ++) {If (prime [I]> = L & prime [I] <= u) {x ++; If (prime [I] % 4 = 1) {Y ++ ;}}if (prime [I]> U) Break ;}if (L <= 2 & U >=2) {y ++ ;} printf ("% d \ n", l, U, x, y);} return 0 ;}