#include <iostream>
#include <cstdint>
using namespace std;
int64_t pows[19];
int64_t licz(int64_t liczba, int pow = 0)
{
if (liczba == 0)
return 1;
if (pows[pow] != 0)
return pows[pow];
int64_t r1 = liczba % 10;
int64_t r2 = liczba % 100;
int64_t suma = (r1+1)*licz(liczba/10, pow+1);
if (r2 >= 10 && r2 <= 18)
suma += (19-r2)*licz(liczba/100, pow+2);
return pows[pow] = suma;
}
int main(int argc, const char* argv[])
{
int liczba;
cin >> liczba;
cout << licz(liczba) << endl;
}
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 | #include <iostream> #include <cstdint> using namespace std; int64_t pows[19]; int64_t licz(int64_t liczba, int pow = 0) { if (liczba == 0) return 1; if (pows[pow] != 0) return pows[pow]; int64_t r1 = liczba % 10; int64_t r2 = liczba % 100; int64_t suma = (r1+1)*licz(liczba/10, pow+1); if (r2 >= 10 && r2 <= 18) suma += (19-r2)*licz(liczba/100, pow+2); return pows[pow] = suma; } int main(int argc, const char* argv[]) { int liczba; cin >> liczba; cout << licz(liczba) << endl; } |
English