asgarlikanan

https://www.e-olymp.com/az/problems/22

Aug 6th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
4CS 0.72 KB | None | 0 0
  1. /*
  2.     Author: Kanan Asgarli
  3.     https://www.e-olymp.com/az/problems/22
  4. */
  5. #include <iostream>
  6. #include <cmath>
  7. #define const 10000
  8.  
  9. using namespace std;
  10. int a, b, p[const+1], res, c;
  11. void primes(){
  12.     p[1] = 1;
  13.     for(int i = 2; i <= (int)sqrt(const); i++)
  14.         if(p[i] == 0)
  15.             for(int j = i*i; j <= const; j += i)
  16.                 p[j] = 1;  
  17. }
  18. int reverse(int n){
  19.     int l = 0, d[5], m = 0, rev = 0;
  20.     while(n > 0){
  21.         d[l++] = n%10;
  22.         n = n/10;
  23.     }
  24.     for(int i = 0; i < l; i++){
  25.         rev = rev*10 +d[i];
  26.     }
  27.     return rev;
  28. }
  29. int main()
  30. {
  31.     primes();
  32.     cin>>a>>b;
  33.     if(a > b)
  34.         swap(a,b);
  35.     for(int i = a; i <= b; i++){
  36.         if(p[i] == 0 && p[reverse(i)] == 0)
  37.             res++;
  38.     }
  39.     cout<<res<<endl;
  40.    
  41.     return 0;
  42. }
Add Comment
Please, Sign In to add comment