Card Divisibility
Time limit1sMemory limit1024 MB
Given consecutive integers from L to R, find the remainder when the number formed by writing them one after another is divided by 9.
- Level
Medium4 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
For every pair of integers and with , there exist unique integers and such that and . This is a simple fact, but you wonder whether you can do something more interesting with this theory.
Right now, you are holding a handful of consecutive cards numbered from to . You lay the cards out side by side and concatenate their digits to form a single large number. You want the remainder when this number is divided by . For example, and means you hold cards 9, 10, and 11. Concatenating them produces 91011, and the remainder when it is divided by 9 is 3.
Input
A single line contains two integers () and (). You hold the cards numbered from to , inclusive.
Output
Print a single line containing the remainder when the concatenated number is divided by .