# 6 points of prime number obtained by screening method, 6 points of prime number obtained by screening method

Source: Internet
Author: User

6 points of prime number obtained by screening method, 6 points of prime number obtained by screening method
11: Prime Number of input objects

• View
• Submit
• Statistics
• Question
Total time limit:
5000 ms

Memory limit:
65536kB
Description
If a number is the same as a number from left to right and a number from right to left, it is called the number of replies. For example, 121,1221 and 15651 are the number of replies. Given the number of digits n, find all the n-digit decimal numbers that are both the return number and the prime number. (Note: If the integer value range is exceeded ).
Input
Number of digits n, where 1 <= n <= 9.
Output
The first line outputs the number of prime numbers that meet the conditions.
The second line outputs all prime numbers that meet the conditions in ascending order. Separate them with a space.
Sample Input
`1`
Sample output
`42 3 5 7`
`1 # include <iostream> 2 # include <cstdio> 3 # include <cmath> 4 # include <cstring> 5 using namespace std; 6 int vis ; 7 int ans ; 8 int now; 9 int tot; 10 int main () 11 {12 int n; 13 cin> n; 14 long int fw = pow (10, n); 15 long int bg = pow (10, n-1); 16 for (int I = 2; I <= sqrt (fw + 0.5); I ++) 17 {18 if (vis [I] = 0) 19 {20 for (int j = I * I; j <= fw; j = j + I) 21 vis [j] = 1; 22} 23} // returns the prime number 24 for (int I = bg; I <= fw; I ++) // each number in the enumerated range is 25 {26 if (vis [I] = 1) continue; 27 else28 {29 int sum = 0, m; 30 m = I; 31 while (m) 32 {33 sum = sum * 10 + m % 10; // sum is 10 times 34 m/= 10 of the sum of the number of repeated single digits plus the sum; // It is reduced by 10 times 35} 36 if (sum = I) 37 {38 tot ++; 39 ans [now] = I; 40 now ++; 41} 42} 43} 44 cout <tot <endl; 45 for (int I = 0; I <now; I ++) 46 cout <ans [I] <"; 47 return 0; 48}`

Related Keywords:
Related Article

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.