Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- long long memo[19];
- long long f(int K){
- if(K <= 1){
- return 0;
- }
- if(memo[K] != -1){
- return memo[K];
- }
- long long ret = 0, aux = 1;
- for(int i=0; i<K-2; i++) aux *= 10;
- for(int i=0; i<=9; i++){
- ret += (9-i)*aux + f(K-2);
- }
- return memo[K] = ret;
- }
- int main(){
- for(int i=0; i<=18; i++){
- memo[i] = -1;
- }
- int K;
- while(scanf("%d", &K) > 0){
- if(K <= 1){
- printf("0\n");
- continue;
- }
- long long ans = 0, aux = 1;
- for(int i=0; i<K-2; i++) aux *= 10;
- for(int i=1; i<=9; i++){
- ans += (9-i)*aux + f(K-2);
- }
- printf("%lld\n", ans);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement