All submissions for this problem are available.
Chef loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let Fd(x) equals to the number of digits d in decimal representation of the positive integer x. Chef interests only in functions F4(x) and F7(x). For the given positive integer N he wants to know the total number of different pairs (L; R) such that F4(L) + F4(L + 1) + ... + F4(R) equals to F7(L) + F7(L + 1) + ... + F7(R) and 1 ≤ L ≤ R ≤ N.
The first line contains a single positive integer T, the number of test cases. T test cases follow. The only line of each test case contains a positive integer N .
For each test case, output a single line containing the answer for the corresponding test case.
1 ≤ T ≤ 100000
1 ≤ N ≤ 100000
Input: 3 3 10 100 Output: 6 31 1266
|Tags||easy, feb12, witua|
|Time Limit:||0.508134 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.