Beauty pageant Prime ~~~~~~~ (⊙o⊙)

Source: Internet
Author: User

Description

Xiao Ming's study of the logarithm of love, a talk about the number, the brain emerges a good majority of the problem, today, Xiao Ming wants to test your understanding of the prime number.The problem is this: a decimal number, if it is prime, and its numbers and is also a prime number, it is called the "United States prime", such as 29, itself is a prime, and 2+9 = 11 is also prime, so it is the United States prime. given an interval, can you figure out how many primes there are in this interval?

Input

The first line enters a positive integer t, which indicates that there is a total of T-group data (T <= 10000).Next, a total of two integers l,r (1<= L <= R <= 1000000) are entered for each line, representing the left and right values of the interval.

Output

For each set of data, the number of case is first output, and then the number of us primes in the interval (including the endpoint value l,r) is output.One row for each group of data, and a specific output format see sample.

Sample Input

31 1002 23 19

Sample Output

Case #1:14Case #2:1Case #3:4 ideas: play the table. The multiples of prime numbers must be composite, and we can use this to mark the composite.
1#include <iostream>2#include <cstring>3 using namespacestd;4 Const intM =1000010;5 intIsprime[m];6 intIsbuprime_sum[m];7 voidPrime ()8 {9memset (IsPrime,0,sizeof(IsPrime));Tenmemset (Isbuprime_sum,0,sizeof(Isbuprime_sum)); Oneisprime[0] =1; Aisprime[1] =1;//Initialize -      for(inti =2; i < M; i++) -     { the         if(Isprime[i])//judge, is composite directly skip -             Continue; -          for(intj = i+i; J < M; J + = i)//mark the multiples of the prime number (that is, composite) first . -         { +ISPRIME[J] =1; -         } +     } A } at  - intSumsum (intk) - { -     intsum =0; -      while(k) -     { inSum + = k%Ten;//each digit of the and, so that the subsequent judgment -K/=Ten; to     } +     returnsum; - } the  * intMain () $ {Panax Notoginseng Prime (); -isbuprime_sum[0] = isbuprime_sum[1] =0; the      for(inti =2; i < M; i++) +     { A         if(!isprime[i] &&!isprime[sumsum (i)])//The former prime number is marked as 0. theIsbuprime_sum[i] = isbuprime_sum[i-1] +1;//It 's the number of dollars in the United States . +         Else -Isbuprime_sum[i] = isbuprime_sum[i-1];//not the number of beautiful primes, the current count is unchanged $     } $     intt,ans=1; -CIN >>T; -      while(t--) the     { -         intR, L;WuyiCIN >> L >>R; thecout <<"Case #"<< ans++ <<": "<< Isbuprime_sum[r]-isbuprime_sum[l-1] << Endl;//output L-1 for including left and right endpoints -  Wu     } -  About     return 0; $}

Experience:

Get a move, you can find the prime number, it is absolutely awesome, haha, the training is too fast, the blink of an eye is almost over. Also really a little reluctant to go home, said more, learn more important knowledge, refueling refueling ~~~~~~~? (^∇^*)

Beauty pageant Prime ~~~~~~~ (⊙o⊙)

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.