cho.sh
Notes
Loading...

Incorrect Josephus Code

Time limit

2s

Memory limit

128 MB

Problem

Suppose the Josephus problem can be solved by the following pseudocode.

text
r := 0for i from 1 to n do    r := (r + k) mod ireturn r

A programmer misread the code and wrote it as follows instead.

text
r := 0for i from 1 to n do    r := r + (k mod i)return r

Given n and k, write a program that prints the value returned by the incorrect code.

Input

The first line contains two integers n and k. (1 <= n, k <= 10^9)

Output

Print the value returned by the incorrect code.

r := 0for i from 1 to n do    r := (r + k) mod ireturn r
r := 0for i from 1 to n do    r := r + (k mod i)return r