Vla_DOS

Untitled

Feb 5th, 2023
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. #include <random>
  5. #include <algorithm>
  6. #include <math.h>
  7. #include <string>
  8. #include <sstream>
  9.  
  10. using namespace std;
  11. int isPalindrom(int a);
  12.  
  13. int count(int a, int b) {
  14.     int count = 0;
  15.     bool prime;
  16.     for (int i = a; i <= b; i++) {
  17.         prime = true;
  18.         double sqrti = sqrt((double)i);
  19.         for (int j = 2; j < sqrti + 1; j++)
  20.             if (i % j == 0) {
  21.                 prime = false;
  22.                 break;
  23.             }
  24.         if (prime)
  25.             count++;
  26.         count += isPalindrom(i);
  27.     }
  28.  
  29.     return count;
  30. }
  31. int isPalindrom(int a) {
  32.     int  b;
  33.     stringstream ss;
  34.  
  35.     b = a;
  36.     while (b > 0)
  37.     {
  38.         ss << b % 10;
  39.         b /= 10;
  40.     }
  41.     ss >> b;
  42.     if (a == b)
  43.         return 1;
  44.     else
  45.         return 0;
  46. }
  47. int getReverse(int n) {
  48.     int r = n % 10;
  49.     while (n /= 10) {
  50.         r = r * 10 + n % 10;
  51.     }
  52.     return r;
  53. }
  54. int main() {
  55.     int a = 0, b = 0;
  56.     cin >> a >> b;
  57.     cout << "count = " << count(a, b);
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment