Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: Kanan Asgarli
- https://www.e-olymp.com/az/problems/33
- */
- #include <iostream>
- #include <cmath>
- #define MAX 500000
- using namespace std;
- int primes[MAX+1], a, b, say;
- void gen_primes(){
- primes[1] = 1;
- for(int i = 2; i <= sqrt(MAX); i++){
- if(primes[i] == 0)
- for(int j = i*i; j <= MAX; j += i)
- primes[j] = 1;
- }
- }
- bool check(int n){
- int d = n%10;
- while(n > 0){
- if(d == 3 && n%10 == 1)
- return false;
- else{
- d = n%10;
- n = n/10;
- }
- }
- return true;
- }
- int main()
- {
- cin>>a>>b;
- if(a > b)
- swap(a,b);
- gen_primes();
- for(int i = a; i <= b; i++){
- if(primes[i] == 0 && check(i) == true)
- say++;
- }
- cout<<say<<endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment