fork download
  1. def f_aux(n, k):
  2. base = (n / (k * 10)) * k
  3. d = n % (k * 10)
  4. if d >= 2*k:
  5. return base + k
  6. elif d >= k:
  7. return base + d%k + 1
  8. return base
  9.  
  10. def f(n):
  11. k = 1
  12. x = 0
  13. while k <= n:
  14. x += f_aux(n, k)
  15. k *= 10
  16. return x
  17.  
  18. print f(12345678901234567890)
Success #stdin #stdout 0.01s 7728KB
stdin
Standard input is empty
stdout
26639231592663923161