Meisu (hangdian 4548)

Source: Internet
Author: User

/* Prime Number
Problem description
James is more interested in logarithm research. When talking about numbers, many problems have emerged in his mind. Today, James wants to test your understanding of prime numbers.
This is the problem: a decimal number, which is assumed to be a prime number. All its numbers and prime numbers are also called "prime number". For example, 29 is a prime number, and 2 + 9 = 11 is also a prime number, so it is a prime number.
Given a given interval, Can you calculate the number of elements in this interval?
 

Input
Enter a positive integer T in the first line, indicating that T groups of data (T <= 10000) are total ).
Next, there are t rows in total, and two integers L and R (1 <= L <= r <= 1000000) are entered in each row, indicating the left and right values of the range.
 

Output
For each group of data, the number of cases is output first, and then the number of elements in the output range (including the endpoint value L, R ).
Each group of data occupies one row. For details about the output format, see the example.
 

Sample Input
3
1 100
2 2
3 19
 

Sample output
Case #1: 14
Case #2: 1
Case #3: 4
*/
# Include <cstdio>
Int s [1000010] = {, 0 };
Int P [1000010];
Int main ()
{
Int A, B, T;
Int I, j, T;
Int m = 0, Kase;
For (I = 2; I * I <1000010; I ++)
{
If (! S [I])
{
For (j = 2 * I; j <1000010; j + = I)
S [J] = 1;
}
}
For (I = 2; I <1000010; I ++)
{
If (! S [I])
{
Int T = I, n = 0;
While (t)
{
N + = T % 10;
T/= 10 ;}
If (! S [N])
{M ++ ;}
}
P [I] = m;
}
Scanf ("% d", & T );
For (Kase = 1; Kase <= T; Kase ++)
{
Scanf ("% d", & A, & B );
Printf ("case # % d: % d \ n", Kase, P [B]-P [A-1]);
}
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.