Total time limit: 1000 ms memory limit: 65536kb describe to judge between 11 and any integer smaller than 1000 and greater than 11, which is both a prime number and a return number. Enter an integer greater than 11 and less than 1000. The number between 11 and the input number is both a prime number and a number of input. Sample input: 999543 sample output: 1610 indicates that there are multiple groups of test data. Use while () to input them cyclically. The number of input is symmetric between the left and right, for example, 292,333.
The data size of this question is not large. You can mark the prime number and then judge it.
The Code is as follows:
#include <iostream>#include <stdio.h>using namespace std;int f[1000]={0};int coun = 0;void init(){ for(int i = 2; i < 1000; i++) { if(f[i] == 0) { for(int j = i+i; j < 1000; j+=i) { f[i] = 1; } } }}int main(){ init(); int n; int coun = 0; while(cin>>n) { coun = 0; for(int i = 11; i < n; i++) { if(f[i] == 0) { if(f[i]/100 == 0) { if(i%10 == i/10) coun++; } else { if(i%10 == i/100) coun++; } } } cout<<coun<<endl; } return 0;}