#B. 回文质数

    Type: Default 3000ms 256MiB

回文质数

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题目描述

因为 151151 既是一个质数又是一个回文数(从左到右和从右到左是看一样的),所以 151151 是回文质数。

写一个程序来找出范围 [a,b](5a<b100,000,000)[a,b] (5 \le a < b \le 100,000,000)间的所有回文质数。

输入格式

第一行输入两个正整数 aabb

输出格式

输出一个回文质数的列表,一行一个。

输入输出样例 #1

输入 #1

5 500

输出 #1

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

说明/提示

Hint 1: Generate the palindromes and see if they are prime.

提示 1: 找出所有的回文数再判断它们是不是质数(素数).

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

提示 2: 要产生正确的回文数,你可能需要几个像下面这样的循环。

题目翻译来自NOCOW。

USACO Training Section 1.5

产生长度为 55 的回文数:

for (d1 = 1; d1 <= 9; d1+=2) {    // 只有奇数才会是素数
     for (d2 = 0; d2 <= 9; d2++) {
         for (d3 = 0; d3 <= 9; d3++) {
           palindrome = 10000*d1 + 1000*d2 +100*d3 + 10*d2 + d1;//(处理回文数...)
         }
     }
 }

题面来源:https://www.luogu.com.cn/problem/P1217

2025春人工智能数学原理与算法Python基础作业

Not Claimed
Status
Done
Problem
4
Open Since
2025-4-3 0:00
Deadline
2025-4-11 23:59
Extension
24 hour(s)