Problem Description
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 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.
 
Input
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≤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).
 
Output
For each test case, you should print first the identifier of the test case and then the sum of all occupied stones' identifiers.
 
Sample Input
3
2 12
9 10
3 60
22 33 66
9 96
81 40 48 32 64 16 96 42 72
 
Sample Output
Case #1: 42
Case #2: 1170
Case #3: 1872
 
Source
 
这个问题根据我的思想就是,先把所有的都算出来然后根据容斥原理就可以做出来了,我们知道这个 走的路都是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删去就行了,但是删去的过程中还是多计算了,然后我感还是套用结论比较好。。
 
 
 
 
 
 
 
 
 

Frogs的更多相关文章

  1. POJ 1659 Frogs' Neighborhood(Havel-Hakimi定理)

    题目链接: 传送门 Frogs' Neighborhood Time Limit: 5000MS     Memory Limit: 10000K Description 未名湖附近共有N个大小湖泊L ...

  2. CF# Educational Codeforces Round 3 F. Frogs and mosquitoes

    F. Frogs and mosquitoes time limit per test 2 seconds memory limit per test 512 megabytes input stan ...

  3. Frogs' Neighborhood

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 7920   Accepted: 33 ...

  4. HDU 5514 Frogs 容斥定理

    Frogs Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5514 De ...

  5. poj 1659 Frogs' Neighborhood (DFS)

    http://poj.org/problem?id=1659 Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total S ...

  6. poj 1659 Frogs' Neighborhood (贪心 + 判断度数序列是否可图)

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 6076   Accepted: 26 ...

  7. codeforces 609F. Frogs and mosquitoes 二分+线段树

    题目链接 F. Frogs and mosquitoes time limit per test 2 seconds memory limit per test 512 megabytes input ...

  8. poj 1659 Frogs' Neighborhood (度序列)

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 7295   Accepted: 31 ...

  9. POJ 1659 Frogs' Neighborhood(度序列组成)

    意甲冠军  中国 依据Havel-Hakimi定理构图即可咯  先把顶点按度数从大到小排序  可图的话  度数大的顶点与它后面的度数个顶点相连肯定是满足的  出现了-1就说明不可图了 #include ...

随机推荐

  1. iReport折线图

    1.拖动组件面板chart到Summary   2.右击-->chart data  单出   3.   4.X轴和Y轴必须是数字 series:系列 连续,串联 category:类型.部门. ...

  2. Elasticsearch的使用场景深入详解

    了解了ES的使用场景,ES的研究.使用.推广才更有价值和意义. 1.场景-:使用Elasticsearch作为主要的后端 传统项目中,搜索引擎是部署在成熟的数据存储的顶部,以提供快速且相关的搜索能力. ...

  3. sysctl.conf和limit.conf备忘待查

    #################################limits.conf设置################################### #修改最大进程和最大文件打开数限制v ...

  4. JDBC executeBatch 抛出异常停止

    进行批量更新的时候发现: addBatch(sql); executeBatch 抛出异常后,剩余的sql没有更新,即出现异常之前的都入库了,异常之后即使有可执行sql都不会执行. 百度资料后了解:这 ...

  5. func 和action 委托的使用

    func 可以带返回值,action  不带返回值 平时我们如果要用到委托一般都是先声明一个委托类型,比如: private delegate string Say(); string说明适用于这个委 ...

  6. Unity中使用扩展方法解决foreach导致的GC

    对于List这种顺序表,我们解决的时候还是可以使用for代替foreach即可.但是对于非顺序表,比如Dictionary或者Set之类,我们可以扩展方法Foreach,ForeachKey和Fore ...

  7. robotium从入门到放弃 二 第一个实例

    1.导入被测试的源码 我们先下载加你计算器源码,下载地址: https://robotium.googlecode.com/files/AndroidCalculator.zip 如果地址被墙无法现在 ...

  8. iOS 之 WebView 简单使用

    1. 代理 UIWebViewDelegate 2. 创建 UIWebView myWebView=[[UIWebView alloc] initWithFrame:CGRectMake(, ,sel ...

  9. YII 1.0 增删改查

    查询 查询多条返回数据集合 //1.该方法是根据一个条件查询一个集合 $admin=Admin::model()->findAll($condition,$params); $admin=Adm ...

  10. javascript的字符串操作

    一,把字符串的首字母大写返回一个新的字符串 1.1简单写法,把一个单词的首字母大写 String.prototype.firstUpperCase = function(){ return this[ ...