当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3511: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 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, 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:

5 = 22 + 1213 = 32 + 2217 = 42 + 1241 = 52 + 42

Whereas the primes 11, 19, 23, and 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.

输入解释

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 LU < 1,000,000.

The last line of the input file includes a dummy test case with both L = U = −1.

输出解释

For each test case, write the result using the following format:

L U x y

where L and U are as specified in the input. x is the total number of primes within the interval [L, U] (inclusive), and y is the total number of primes (also within [L, U]) that can be expressed as a sum of squares.

输入样例
10 20
11 19
100 1000
-1 -1
输出样例
10 20 4 2
11 19 4 2
100 1000 143 69

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3511

最后修改于 2020-10-29T07:03:17+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536