CCO Preparation Test 2 P1 - Concatenation

View as PDF

Submit solution

Points: 17 (partial)
Time limit: 0.6s
Memory limit: 128M

Author:
Problem types

Bruce always comes up with new challenges for his students. On Saturday's class, Bruce gives Timothy two positive integers N and M, and asks Timothy to calculate the Concat(1,N) mod M, where Concat(1,N) is the concatenation of all positive integers from 1 to N. For example, Concat(1,10)=12345678910. Timothy is so smart that he immediately realizes that it is impossible to calculate the result by hand. Can you help Timothy to write a program to solve this question?

Input Specification

The input will consist of two integers, N and M, in one line.

In 30% of the test cases, 1N1000000.

In 100% of the test cases, 1N1018 and 1M109.

Output Specification

Output one integer, the result of Concat(1,N)(modM).

Sample Input 1

Copy
13 13

Sample Output 1

Copy
4

Sample Input 2

Copy
12345678910 1000000000

Sample Output 2

Copy
345678910

Comments

There are no comments at the moment.