Chef and Numbers
All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes problems related to numbers a lot. He is generally quite good at solving these kinds of problems, but today he got stuck at one number theory problem, and so he asks your help to solve it.
Given a positive integer N, find out how many positive integers X satisfy the equation X + S(X) + S(S(X)) = N, where S(X) denoting sum of digits of X in decimal (base 10) representation.
The only line of the input contains one integer number - N.
Output single integer in a line denoting the count of number of positive integers X satisfying the above given equation.
- 1 ≤ N ≤ 109
Input: 6 Output: 1
Input: 9939 Output: 4
Example 1. Only one positive integer X = 2 satisfies the equation X + S(X) + S(S(X)) = 6, as X + S(X) + S(S(X)) = 2 + 2 + 2 = 6.
Example 2.X can be 9898, 9907, 9910 and 9913.
9898 + S(9898) + S(S(9898)) = 9898 + 34 + 7 = 9939
9907 + S(9907) + S(S(9907)) = 9907 + 25 + 7 = 9939
9910 + S(9910) + S(S(9910)) = 9910 + 19 + 10 = 9939
9913 + S(9913) + S(S(9913)) = 9913 + 22 + 4 = 9939
You can verify that there is not other positive value of X satisfying the given equation.
|Tags||ad-hoc, cook72, easy, mgch|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.5, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.