Time Limit: 1000MS
Memory Limit: 65536K
r := 0; for i from 1 to n do r := (r + k) mod i; return r;Here "x mod y" is the remainder of the division of x by y, But Joseph is not very smart. He learned the algorithm, but did not learn the reasoning behind it. Thus he has forgotten the details of the algorithm and remembers the solution just approximately. He told his friend Andrew about the problem, but claimed that the solution can be found using the following algorithm:
r := 0; for i from 1 to n do r := r + (k mod i); return r;Of course, Andrew pointed out that Joseph was wrong. But calculating the function Joseph described is also very interesting. Given n and k, find ∑1<=i<=n(k mod i).