编程介的小学生 2017-08-25 03:11 采纳率: 20.5%
浏览 754
已采纳

Good Rectangle

We need k square pieces cut from a rectangular piece of paper with length a and width b. Here we assume a is greater than b. Obviously, the biggest side length of a square we can get is b, so the length a of the rectangular piece must be greater than k × b. And after k squares got, the rest part of original rectangle should be a rectangular piece with length b and width c = a - b × k. Here we assume b is not less than c, or we will waste too much. To reuse the rest part, we want the rest rectangle is similar to the original rectangle, but it is impossible (can you prove?).

To measure how similar is the rest rectangle to the original rectangle, we define best(b) = min {abs( b ÷ ( x - k × b ) - x ÷ b ) | for x ≥ k × b}. We call b is a good width if best(b) is less than best(d) for any positive d less than b. And if a rectangle with a good width b and a length a which makes abs(b ÷ (a - k × b) - a ÷ b) minimal, it is a good rectangle. We can get the result easily for each good width, a good rectangle can be got. And we sort the good rectangles by its width from small to large. Now given k, can you calculate area of the nth good rectangle? (all variables above is integer)

Input

There are no more than test cases. Each test case has only one line, containing two integers k and n (0 < k < 1000001, 0 < n < 1000001).

Output

Output one line for each case, each case need only a number contained one integer S, which indicates the area of the nth good rectangle. S may be very large, so print S MOD 9875321.

Sample Input

1 10
2 1
Sample Output

12816
3

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab