fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. /*
  5.   lời giải dưới chỉ áp dụng cho sub1 (L, R <= 2e3)
  6.   Không thể giải sub cuối!!! (hoặc có)
  7. */
  8.  
  9. int reverse_number(int x) {
  10. int res = 0;
  11. while(x > 0) res = res * 10 + (x % 10), x /= 10;
  12. return res;
  13. }
  14.  
  15. bool is_prime(int x) {
  16. for(int i=2;i<=sqrt(x);i++) if(x % i == 0) {
  17. return false;
  18. }
  19.  
  20. if(x == 1) return false;
  21. return true;
  22. }
  23.  
  24. int32_t main() {
  25. int L, R; cin >> L >> R;
  26. int reverse_primes = 0;
  27.  
  28. for(int i = L; i <= R; i++) {
  29. int num_after_reverse = reverse_number(i);
  30.  
  31. if(is_prime(num_after_reverse)) {
  32. reverse_primes++;
  33. }
  34. }
  35.  
  36. cout << reverse_primes;
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5316KB
stdin
20 35
stdout
6