#include <iostream>
using namespace std;
unsigned long long potega(int x, int c)
{
unsigned long long wynik=1;
for(int i=0; i<c; i++)
{
wynik*=x;
}
return wynik;
}
int ilosc_cyfr(unsigned long long a)
{
int i=1;
while(potega(10, i)<=a)
{
i++;
}
return i;
}
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
unsigned long long l, r, liczba_liczb=0;
std::cin>>l>>r;
int cyfra;
bool jestem;
for(l; l<=r; l++) {
int x=ilosc_cyfr(l);
cyfra=(l%potega(10,x))/potega(10,x-1);
if(cyfra!=0 && l%cyfra==0) jestem=true;
else jestem=false;
while(jestem==true && x>1)
{
x-=1;
cyfra=(l%potega(10,x))/potega(10,x-1);
if(cyfra!=0 && l%cyfra==0) jestem=true;
else jestem=false;
}
if(jestem==true) liczba_liczb++;
}
std::cout<<liczba_liczb;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | #include <iostream> using namespace std; unsigned long long potega(int x, int c) { unsigned long long wynik=1; for(int i=0; i<c; i++) { wynik*=x; } return wynik; } int ilosc_cyfr(unsigned long long a) { int i=1; while(potega(10, i)<=a) { i++; } return i; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); unsigned long long l, r, liczba_liczb=0; std::cin>>l>>r; int cyfra; bool jestem; for(l; l<=r; l++) { int x=ilosc_cyfr(l); cyfra=(l%potega(10,x))/potega(10,x-1); if(cyfra!=0 && l%cyfra==0) jestem=true; else jestem=false; while(jestem==true && x>1) { x-=1; cyfra=(l%potega(10,x))/potega(10,x-1); if(cyfra!=0 && l%cyfra==0) jestem=true; else jestem=false; } if(jestem==true) liczba_liczb++; } std::cout<<liczba_liczb; return 0; } |
English