Advertisement
Josif_tepe

Untitled

Apr 5th, 2021
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int L, R;
  8.     cin >> L >> R;
  9.     int count_zimson = 0;
  10.     for(int i = L; i <= R; i++) {
  11.         int tmp = i;
  12.         int divisible = 0;
  13.         while(tmp > 0) {
  14.             int digit = tmp % 10;
  15.             if(digit != 0 and i % digit == 0) {
  16.                 divisible = 1;
  17.             }
  18.             else {
  19.                 divisible = 0;
  20.                 break;
  21.             }
  22.             tmp /= 10;
  23.         }
  24.         if(divisible == 1) {
  25.             count_zimson++;
  26.             continue;
  27.         }
  28.         int niza[6];
  29.         tmp = i;
  30.         int c = 0;
  31.         while(tmp > 0) {
  32.             niza[c] = tmp % 10;
  33.             tmp /= 10;
  34.             c++;
  35.         }
  36.         int l = 0, r = c - 1;
  37.         int is_palindrome = 0;
  38.         while(l <= r) {
  39.             if(niza[l] == niza[r]) {
  40.                 l++;
  41.                 r--;
  42.                 is_palindrome = 1;
  43.             }
  44.             else {
  45.                 is_palindrome = 0;
  46.                 break;
  47.             }
  48.         }
  49.         if(is_palindrome == 1) {
  50.             count_zimson++;
  51.         }
  52.     }
  53.     cout << count_zimson << endl;
  54.     return 0;
  55. }
  56. /*
  57.  
  58.  **/
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement