codeforces-scrape

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

1213C.md (1206B)


      1 Source: https://codeforces.com/problemset/problem/1213/C
      2 
      3 C. Book Reading
      4 
      5 time limit per test
      6 
      7 1 second
      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 Polycarp is reading a book consisting of $n$ pages numbered from $1$ to $n$. Every time he finishes the page with the number divisible by $m$, he writes down the last digit of this page number. For example, if $n=15$ and $m=5$, pages divisible by $m$ are $5, 10, 15$. Their last digits are $5, 0, 5$ correspondingly, their sum is $10$.
     22 
     23 Your task is to calculate the sum of all digits Polycarp has written down.
     24 
     25 You have to answer $q$ independent queries.
     26 
     27 Input
     28 
     29 The first line of the input contains one integer $q$ ($1 \le q \le 1000$) — the number of queries.
     30 
     31 The following $q$ lines contain queries, one per line. Each query is given as two integers $n$ and $m$ ($1 \le n, m \le 10^{16}$) — the number of pages in the book and required divisor, respectively.
     32 
     33 Output
     34 
     35 For each query print the answer for it — the sum of digits written down by Polycarp.
     36 
     37 Example
     38 
     39 Input
     40 
     41 ```
     42 7
     43 1 1
     44 10 1
     45 100 3
     46 1024 14
     47 998244353 1337
     48 123 144
     49 1234312817382646 13
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 1
     56 45
     57 153
     58 294
     59 3359835
     60 0
     61 427262129093995
     62 ```