#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
string n, odp(30, '0');
int dl;
string NaStr(ll x)
{
if (x == 0)
return "0";
string wyn = "";
while (x != 0)
{
wyn = (char) (x % 10 + '0') + wyn;
x /= 10;
}
while (wyn.size() < 30)
wyn = "0" + wyn;
return wyn;
}
void Dodaj(string x)
{
int p = 0;
for (int i = 29; i >= 0; --i)
{
int d = (x[i] - '0') + (odp[i] - '0') + p;
odp[i] = (char) (d % 10 + '0');
p = d / 10;
}
}
void rec(vector<int>& c, int x, int s)
{
c.push_back(x);
if (s == dl)
{
ll ilo = 1;
int p = 0;
for (int i = 0; i < c.size(); ++i)
{
int li;
ll spo = 0;
if (c[i] == 1)
li = n[p] - '0';
else
li = 10 * (n[p + 1] - '0') + (n[p] - '0');
for (int c = 0; c <= 9; ++c)
if (li - c >= 0 && li - c <= 9)
++spo;
ilo *= spo;
p += c[i];
}
Dodaj(NaStr(ilo));
c.pop_back();
return;
}
rec(c, 1, s + 1);
if (s + 2 <= dl && n[s + 1] == '1' && n[s] <= '8')
rec(c, 2, s + 2);
c.pop_back();
}
int main()
{
ios_base::sync_with_stdio(0);
cin >> n;
dl = n.size();
reverse(n.begin(), n.end());
vector<int> c;
rec(c, 1, 1);
if (dl >= 2 && n[1] == '1' && n[0] <= '8')
rec(c, 2, 2);
while (odp[0] == '0')
odp.erase(0, 1);
cout << odp;
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; string n, odp(30, '0'); int dl; string NaStr(ll x) { if (x == 0) return "0"; string wyn = ""; while (x != 0) { wyn = (char) (x % 10 + '0') + wyn; x /= 10; } while (wyn.size() < 30) wyn = "0" + wyn; return wyn; } void Dodaj(string x) { int p = 0; for (int i = 29; i >= 0; --i) { int d = (x[i] - '0') + (odp[i] - '0') + p; odp[i] = (char) (d % 10 + '0'); p = d / 10; } } void rec(vector<int>& c, int x, int s) { c.push_back(x); if (s == dl) { ll ilo = 1; int p = 0; for (int i = 0; i < c.size(); ++i) { int li; ll spo = 0; if (c[i] == 1) li = n[p] - '0'; else li = 10 * (n[p + 1] - '0') + (n[p] - '0'); for (int c = 0; c <= 9; ++c) if (li - c >= 0 && li - c <= 9) ++spo; ilo *= spo; p += c[i]; } Dodaj(NaStr(ilo)); c.pop_back(); return; } rec(c, 1, s + 1); if (s + 2 <= dl && n[s + 1] == '1' && n[s] <= '8') rec(c, 2, s + 2); c.pop_back(); } int main() { ios_base::sync_with_stdio(0); cin >> n; dl = n.size(); reverse(n.begin(), n.end()); vector<int> c; rec(c, 1, 1); if (dl >= 2 && n[1] == '1' && n[0] <= '8') rec(c, 2, 2); while (odp[0] == '0') odp.erase(0, 1); cout << odp; return 0; } |
English