编程介的小学生 2017-09-21 23:36 采纳率: 20.5%
浏览 764
已采纳

Fermat's Christmas Theorem

Description

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 + 12 13 = 32 + 22 17 = 42 + 12 41 = 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.

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 includes a dummy test case with both L = U = −1.

Output

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, and y is the total number of primes (also within [L, U]) that can be expressed as a sum of squares.

Sample Input

10 20
11 19
100 1000
-1 -1
Sample Output

10 20 4 2
11 19 4 2
100 1000 143 69

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-10-08 00:28
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧