fork download
  1. def solve( x ):
  2. s, a, b, c = 0, 0, 10, 1
  3. while x >= b:
  4. s += (b - a) // 2 * c
  5. a = b
  6. b *= 10
  7. c += 1
  8. return s + (x - a + 1) // 2 * c
  9.  
  10. def ask( x ):
  11. print( '{} => {}'.format( x, solve(x) ) )
  12.  
  13. ask(3)
  14. ask(10)
  15. ask(9999)
  16. ask(123456789)
  17. ask(31415926535897)
  18.  
Success #stdin #stdout 0.02s 27704KB
stdin
Standard input is empty
stdout
3 => 2
10 => 5
9999 => 19445
123456789 => 500000000
31415926535897 => 214355930195731