Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: Kanan Asgarli
- https://www.e-olymp.com/az/problems/22
- */
- #include <iostream>
- #include <cmath>
- #define const 10000
- using namespace std;
- int a, b, p[const+1], res, c;
- void primes(){
- p[1] = 1;
- for(int i = 2; i <= (int)sqrt(const); i++)
- if(p[i] == 0)
- for(int j = i*i; j <= const; j += i)
- p[j] = 1;
- }
- int reverse(int n){
- int l = 0, d[5], m = 0, rev = 0;
- while(n > 0){
- d[l++] = n%10;
- n = n/10;
- }
- for(int i = 0; i < l; i++){
- rev = rev*10 +d[i];
- }
- return rev;
- }
- int main()
- {
- primes();
- cin>>a>>b;
- if(a > b)
- swap(a,b);
- for(int i = a; i <= b; i++){
- if(p[i] == 0 && p[reverse(i)] == 0)
- res++;
- }
- cout<<res<<endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment