10123_PrimePalindromes

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

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

Pro.ID

10123

Title

Prime Palindromes

Title链接

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

AC

105

Submit

370

Ratio

28.38%

时间&空间限制

  • Time Limit: 400/200 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others)
  • 描述

    The number 151 is a prime palindrome because it is both a prime number and a palindrome (it is the same number when read forward as backward). Write a program that finds all prime palindromes in the range of two supplied numbers a and b ( 5 ≤ a < b ≤ 100000000 ); both a and b are considered to be within the range.

    输入

    Multiple test cases. Each case on one line:

    Two integers, a and b

    输出

    Description

    The number 151 is a prime palindrome because it is both a prime number and a palindrome (it is the same number when read forward as backward). Write a program that finds all prime palindromes in the range of two supplied numbers a and b ( 5 ≤ a < b ≤ 100000000 ); both a and b are considered to be within the range.

    Input

    Multiple test cases. Each case on one line:

    Two integers, a and b

    Output

    For each case, output the list of palindromic primes in numerical order, one per line.

    After each case, output one blank line.

    Sample Input

    5 500
    750 14000

    Sample Output

    5
    7
    11
    101
    131
    151
    181
    191
    313
    353
    373
    383

    757
    787
    797
    919
    929
    10301
    10501
    10601
    11311
    11411
    12421
    12721
    12821
    13331
    13831
    13931

    Hint

    Generate the palindromes and see if they are prime.

    Generate palindromes by combining digits properly. You might need more than one of the loops like below.

    /* generate five digit palindrome: */
    for (d1 = 1; d1 <= 9; d1+=2) { /* only odd; evens aren't so prime */
       for (d2 = 0; d2 <= 9; d2++) {
           for (d3 = 0; d3 <= 9; d3++) {
               palindrome = 10000*d1 + 1000*d2 +100*d3 + 10*d2 + d1;
               ... deal with palindrome ...
           }
       }
    }

    Source

    样例输入

    5 500
    750 14000

    样例输出

    5
    7
    11
    101
    131
    151
    181
    191
    313
    353
    373
    383

    757
    787
    797
    919
    929
    10301
    10501
    10601
    11311
    11411
    12421
    12721
    12821
    13331
    13831
    13931

    提示

    Generate the palindromes and see if they are prime.

    Generate palindromes by combining digits properly. You might need more than one of the loops like below.

    /* generate five digit palindrome: */
    for (d1 = 1; d1 <= 9; d1+=2) { /* only odd; evens aren't so prime */
       for (d2 = 0; d2 <= 9; d2++) {
           for (d3 = 0; d3 <= 9; d3++) {
               palindrome = 10000*d1 + 1000*d2 +100*d3 + 10*d2 + d1;
               ... deal with palindrome ...
           }
       }
    }


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部