题解:Digit Primes(数字素数)

本问题要求找出在指定范围内(小于1000000)的数字素数数量。数字素数是其数字之和也构成素数的素数。例如,41是一个数字素数,因为4+1=5,而5是素数。题目提供输入文件,包含多个测试用例,每个用例给出两个整数t1和t2,需要计算t1到t2(含)之间的数字素数个数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A prime number is a positive number, which is divisible by exactly two different integers. A digit prime is a prime number whose sum of digits is also prime. For example the prime number 41 is a digit prime because 4 + 1 = 5 and 5 is a prime number. 17 is not a digit prime because 1 + 7 = 8, and 8 is not a prime number. In this problem your job is to find out the number of digit primes within a certain range less than 1000000.
Input First line of the input file contains a single integer N (0 < N ≤ 500000) that indicates the total number of inputs. Each of the next N lines contains two integers t1 and t2 (0 < t1 ≤ t2 < 1000000).
Output
For each line of input except the first line produce one line of output containing a single integer that indicates the number of digit primes between t1 and t2 (inclusive).
Sample Input
3 10 20 10 100 100 10000
Sample Output
1 10 576
Note: You should at least use scanf() and printf() to take input and produce output

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值