#include <bits/stdc++.h> #define lld long long int using namespace std; lld N; lld DP[30]; lld pop=-1; lld ind=1; lld akt; int main() { scanf("%lld",&N); DP[0]=1; while(N>0) { akt=N%10; N/=10; if(pop==-1) DP[ind]=akt+1; else { DP[ind]=DP[ind-1]*(akt+1); if(akt==1 and pop<9) { DP[ind]+=DP[ind-2]*(18-(akt*10+pop)+1); } } pop=akt; ++ind; } printf("%lld\n",DP[ind-1]); }
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 <bits/stdc++.h> #define lld long long int using namespace std; lld N; lld DP[30]; lld pop=-1; lld ind=1; lld akt; int main() { scanf("%lld",&N); DP[0]=1; while(N>0) { akt=N%10; N/=10; if(pop==-1) DP[ind]=akt+1; else { DP[ind]=DP[ind-1]*(akt+1); if(akt==1 and pop<9) { DP[ind]+=DP[ind-2]*(18-(akt*10+pop)+1); } } pop=akt; ++ind; } printf("%lld\n",DP[ind-1]); } |