codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1538F.md (1324B)


      1 Source: https://codeforces.com/problemset/problem/1538/F
      2 
      3 F. Interesting Function
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You are given two integers $l$ and $r$, where $l \lt r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.
     22 
     23 For example:
     24 
     25 * if $l=909$, then adding one will result in $910$ and $2$ digits will be changed;
     26 * if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed;
     27 * if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed.
     28 
     29 Changed digits always form a suffix of the result written in the decimal system.
     30 
     31 Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time.
     32 
     33 Input
     34 
     35 The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.
     36 
     37 Each test case is characterized by two integers $l$ and $r$ ($1 \le l \lt r \le 10^9$).
     38 
     39 Output
     40 
     41 For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time.
     42 
     43 Example
     44 
     45 Input
     46 
     47 ```
     48 4
     49 1 9
     50 9 10
     51 10 20
     52 1 1000000000
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 8
     59 2
     60 11
     61 1111111110
     62 ```