Advertisement
Josif_tepe

Untitled

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