HDU 5656
CA Loves GCD
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 809 Accepted Submission(s): 283
Now, there are N
different numbers. Each time, CA will select several numbers (at least one), and find the GCD of these numbers. In order to have fun, CA will try every selection. After that, she wants to know the sum of all GCDs.
If and only if there is a number exists in a selection, but does not exist in another one, we think these two selections are different from each other.
denoting the number of testcases.
T
testcases follow. Each testcase contains a integer in the first time, denoting N
, the number of the numbers CA have. The second line is N
numbers.
We guarantee that all numbers in the test are in the range [1,1000].
1≤T≤50
lines, each line prints the sum of GCDs mod 100000007
.
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<set>
#define ll __int64
#define mod 100000007
using namespace std;
ll dp[][];
int a[];
int maxn;
int t,n;
ll ans=;
ll gcd(ll aa,ll bb)// 求解gcd
{
ll exm;
if(aa<bb)
{
exm=aa;
aa=bb;
bb=exm;
}
if(bb==)
return aa;
gcd(bb,aa%bb);
}
int main()
{
while(scanf("%d",&t)!=EOF)
{
for(int i=; i<=t; i++)
{
ans=;
memset(dp,,sizeof(dp));
memset(a,,sizeof(a));
scanf("%d",&n);
maxn=-;
for(int j=; j<=n; j++)
{
scanf("%d",&a[j]);
if(a[j]>maxn)
maxn=a[j];
dp[j][a[j]]=;//初始化 只取第j个a[j]
}
for(int j=; j<=n; j++)
{
int v=a[j+];
for(int k=; k<=maxn; k++)
{
dp[j+][k]=(dp[j+][k]+dp[j][k])%mod;
if(dp[j][k])
{int gg=gcd(k,v);
dp[j+][gg]=(dp[j+][gg]+dp[j][k])%mod;}
}
}
for(int j=; j<=maxn; j++)
ans=(ans+j*dp[n][j])%mod;
printf("%I64d\n",ans);
}
}
return ;
}
HDU 5656的更多相关文章
- hdu 5656 CA Loves GCD(n个任选k个的最大公约数和)
CA Loves GCD Accepts: 64 Submissions: 535 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 2 ...
- HDU 5656 CA Loves GCD 01背包+gcd
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5656 bc:http://bestcoder.hdu.edu.cn/contests/con ...
- HDU 5656 CA Loves GCD dp
CA Loves GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5656 Description CA is a fine comrade w ...
- CA Loves GCD (BC#78 1002) (hdu 5656)
CA Loves GCD Accepts: 135 Submissions: 586 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: ...
- HDU 5656 CA Loves GCD (数论DP)
CA Loves GCD 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/B Description CA is a fine c ...
- 数学(GCD,计数原理)HDU 5656 CA Loves GCD
CA Loves GCD Accepts: 135 Submissions: 586 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 2621 ...
- hdu 5656 CA Loves GCD(dp)
题目的意思就是: n个数,求n个数所有子集的最大公约数之和. 第一种方法: 枚举子集,求每一种子集的gcd之和,n=1000,复杂度O(2^n). 谁去用? 所以只能优化! 题目中有很重要的一句话! ...
- HDU 5656 CA Loves GCD (容斥)
题意:给定一个数组,每次他会从中选出若干个(至少一个数),求出所有数的GCD然后放回去,为了使自己不会无聊,会把每种不同的选法都选一遍,想知道他得到的所有GCD的和是多少. 析:枚举gcd,然后求每个 ...
- HDU 5656 ——CA Loves GCD——————【dp】
CA Loves GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
随机推荐
- Font Awesome 完美的图标字体
好久没来,虽说鄙人的人气不咋地,但还是很想念自己这一亩二分田地. 近期用在平台开发中,看着设计师摆开阵势,准备大画图标,想着自己将会很KUBI拼凑css-sprite图片,接着写一大堆 class^= ...
- 单元测试模块unittest使用学习
工作原理: unittest中最核心的四个概念是:test case, test suite, test runner, test fixture. 一个TestCase的实例就是一个测试用例.什么是 ...
- Case 降序升序排列
select nc.Class_Name,hn.home_news_id,hn.hemo_id,hn.hemo_Date, hn.hemo_title,hemo_order from Hemo_New ...
- SpringBoot在IDEA下使用JPA
1依赖 使用IDEA构建基于JPA的项目需要引用JPA.MYSQL依赖 2配置文件修改 2.1连接库 spring.datasource.url=jdbc:mysql://localhost:3306 ...
- 七:HDFS Permissions Guide 权限
1.权限模式 简单:启动HDFS的操作系统用户即为超级用户,可以通过HADOOP_USER_NAME指定 kerberos: 2.group mapping 组列表由grou ...
- 1.安装CDH5.12.x
安装方式安装前准备安装步骤安装过程修改/etc/hosts设置ssh 互信修改linux 系统设置安装JDK1.8安装python2.7安装mysql/postgreysql数据库安装ntp设置本地y ...
- week1 四人小组项目
小组名称:nice! 项目组长:李权 组员:于淼 刘芳芳 杨柳 项目选题:东北师范大学论坛 作为东北师范大学同学间的信息交流平台,要满足的需求如下: 1.校内信息及公告 2.毕业生招聘信息 3.课程查 ...
- 在vue项目中使用monaco-editor
monaco-editor: https://github.com/Microsoft/monaco-editor 在ESM中的使用官方也有对应文档:https://github.com/Micros ...
- 提升MyEclipse运行速度
修改MyEclipse.ini文件中的,将-vmargs后面的参数修改为 -Xms256m -Xmx768m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:Max ...
- 只有父类的init方法才有创建servletConfig与servletContext的能力
如果重写了父类的init方法 但又没有显示调用父类的init方法 那么子类无法使用servletContext 因为 子类方法没有创建出 servletConfig