当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5514:Frogs

题目描述
There are $m$ stones lying on a circle, and $n$ frogs are jumping over them.
The stones are numbered from $0$ to $m-1$ and the frogs are numbered from $1$ to $n$. The $i$-th frog can jump over exactly $a_i$ stones in a single step, which means from stone $j~mod~m$ to stone $(j+a_i)~mod~m$ (since all stones lie on a circle).

All frogs start their jump at stone $0$, then each of them can jump as many steps as he wants. A frog will occupy a stone when he reach it, and he will keep jumping to occupy as much stones as possible. A stone is still considered ``occupied" after a frog jumped away.
They would like to know which stones can be occupied by at least one of them. Since there may be too many stones, the frogs only want to know the sum of those stones' identifiers.
输入解释
There are multiple test cases (no more than $20$), and the first line contains an integer $t$,
meaning the total number of test cases.

For each test case, the first line contains two positive integer $n$ and $m$ - the number of frogs and stones respectively $(1\le n\le 10^4,~1\le m\le 10^9)$.

The second line contains $n$ integers $a_1,a_2,\cdots,a_n$, where $a_i$ denotes step length of the $i$-th frog $(1\le a_i\le 10^9)$.
输出解释
For each test case, you should print first the identifier of the test case and then the sum of all occupied stones' identifiers.
输入样例
3
2 12
9 10
3 60
22 33 66
9 96
81 40 48 32 64 16 96 42 72
输出样例
Case #1: 42
Case #2: 1170
Case #3: 1872
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5514

最后修改于 2020-10-25T23:23:19+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 65536/65536K(Java/Others)