22397_Fermat'sChirstmasTheore

2022-5-16 18:21| 发布者: Hocassian| 查看: 20| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506393973999-Problem List-采集的数据-后羿采集器.html

Pro.ID

22397

Title

Fermat's Chirstmas Theorem

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22397

AC

0

Submit

7

Ratio

0.00%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    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.

    输入

    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.

    输出

    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 LU < 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] (inclusive,) 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

    Source

    样例输入

    10 20
    11 19
    100 1000
    -1 -1

    样例输出

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

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部