首页 技术 正文
技术 2022年11月19日
0 收藏 826 点赞 2,167 浏览 1767 个字

Problem DescriptionThere 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 ai stones in a single step, which means from stone j mod m to stone (j+ai) 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. InputThere 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≤n≤104, 1≤m≤109).

The second line contains n integers a1,a2,⋯,an, where ai denotes step length of the i-th frog (1≤ai≤109). OutputFor each test case, you should print first the identifier of the test case and then the sum of all occupied stones’ identifiers. Sample Input3
2 12
9 10
3 60
22 33 66
9 96
81 40 48 32 64 16 96 42 72 Sample OutputCase #1: 42
Case #2: 1170
Case #3: 1872 Source 2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)  这个问题根据我的思想就是,先把所有的都算出来然后根据容斥原理就可以做出来了,我们知道这个 走的路都是K*gcd(a[i],m);我们可以这样子推道一下,假设m%a[i]==0  那么这个青蛙走的距离就是a[i]的倍数,我们可以假设一下啊,这是走的最优解,要是  gcd(a[i],m)==1这样子的话就是相当于a[i]=a[i]*1; 这样子的话我们可以把所有的解都能求出来了。综上我们知道所有的结果就是k*gcd(a[i],m); 要是m小一点的话,我们就能枚举m得到所有的解,但是现在的话根本就是不可以的。首先我是这样子想的就是要是gcd(a[i],m)==1的时候这个时候就是0–m-1等差求和,其他的时候就是枚举m的所有   机智的我打了一个表,然后发现1e9以内的因子,不过1e3个好像最多的1024吧,,,看到这里真的是太高兴了,,,,OK现在我就是开始枚举因子,然后感觉不用什么容斥定理就可以AC了,感觉随便的加加减减就被被人称为容斥定理,但是我感觉真的就是加加减减。 今天下午好好的想一下这个问题,然后就是再做2个问题。。。我们假设  3 6     和  2  4   6  我们我们算完2再算3的时候发现6倍多算了一次,然后我们再减去就行了,我还是想简单了,我以为只要把6和4,6删去就行了,但是删去的过程中还是多计算了,然后我感还是套用结论比较好。。         

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,581
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918