DMPG '18 B2 - Mimi and Modulus

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

The modulo operator is a very commonly used operation in computer science. The result of taking A modulo B is equal to the remainder of A when divided by B.

For her ICS homework, Mimi was asked the find the greatest result of A mod M for all integers A in the range 1, 2, 3, \ldots N-1, N. Can you help Mimi do her homework?

Constraints

Subtask 1 [40%]

1 \le N, M \le 10^5

Subtask 2 [60%]

1 \le N, M \le 10^9

Input Specification

The first and only line of input will contain two space separated integers, N and M.

Output Specification

The greatest result of A mod M for all integers A in the range 1, 2, 3, \ldots N-1, N.

Sample Input

5 3

Sample Output

2

Comments

There are no comments at the moment.