#include <iostream> #define ll long long using namespace std; ll na_ile (ll x) { if (x<10) return x+1; if (x>18) return 0; return 19-x; } int main () { //cout << na_ile (12)<<endl; //cout << na_ile (11)<<endl; //cout << na_ile (1)<<endl; //cout << na_ile (2)<<endl; ll n; cin >> n; if (n<10) { cout << n+1; return 0; } ll prelast = na_ile (n%10); ll last = na_ile (n%100) + prelast * na_ile((n/10)%10); n/=10; while (n>9) { ll newlast = prelast*na_ile(n%100) + last*na_ile((n/10)%10); prelast = last; last = newlast; n/=10; } cout << last; 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 | #include <iostream> #define ll long long using namespace std; ll na_ile (ll x) { if (x<10) return x+1; if (x>18) return 0; return 19-x; } int main () { //cout << na_ile (12)<<endl; //cout << na_ile (11)<<endl; //cout << na_ile (1)<<endl; //cout << na_ile (2)<<endl; ll n; cin >> n; if (n<10) { cout << n+1; return 0; } ll prelast = na_ile (n%10); ll last = na_ile (n%100) + prelast * na_ile((n/10)%10); n/=10; while (n>9) { ll newlast = prelast*na_ile(n%100) + last*na_ile((n/10)%10); prelast = last; last = newlast; n/=10; } cout << last; return 0; } |