asgarlikanan

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

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