hdu 5656 CA Loves GCD
CA Loves GCD
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 882 Accepted Submission(s):
305
inevitably she loves GCD (greatest common divisor) too.
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 <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#define mod 100000007
using namespace std; int xx(int a,int b)
{
int c,t;
if(a<b)
{
t=a;
a=b;
b=t;
}
while(b)
{
c=a%b;
a=b;
b=c;
}
return a;
} int main()
{
int T,i,j,a,b,k,n,m,w;
int ai[];
long long vis[];
scanf("%d",&T);
while(T--)
{
long long sum=;
scanf("%d",&n);
memset(vis,,sizeof(vis));
for(i=; i<n; i++)
{
scanf("%d",&ai[i]);
}
for(i=; i<n; i++)
{
for(j=; j<=; j++)
if(vis[j])
{
vis[xx(ai[i],j)]=(vis[xx(ai[i],j)]+vis[j])%mod;
}
vis[ai[i]]=(vis[ai[i]]+)%mod;
}
for(i=; i<=; i++)
if(vis[i])
sum=(sum+(i*vis[i])%mod)%mod;
printf("%I64d\n",sum);
}
}
hdu 5656 CA Loves GCD的更多相关文章
- 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 ...
- 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】
CA Loves GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- hdu 5656 CA Loves GCD(dp)
题目的意思就是: n个数,求n个数所有子集的最大公约数之和. 第一种方法: 枚举子集,求每一种子集的gcd之和,n=1000,复杂度O(2^n). 谁去用? 所以只能优化! 题目中有很重要的一句话! ...
- HDU 5656 CA Loves GCD (容斥)
题意:给定一个数组,每次他会从中选出若干个(至少一个数),求出所有数的GCD然后放回去,为了使自己不会无聊,会把每种不同的选法都选一遍,想知道他得到的所有GCD的和是多少. 析:枚举gcd,然后求每个 ...
- CA Loves GCD (BC#78 1002) (hdu 5656)
CA Loves GCD Accepts: 135 Submissions: 586 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: ...
随机推荐
- AspNet 常有功能函数1.0
1.net 获取客户端ip方法(此方法不是很准确) public static string GetIP() { string str; if (!string.IsNullOrEmpty(HttpC ...
- Thread.sleep
Thread.sleep() The current thread changes state from Running to Waiting/Blocked as shown in the diag ...
- 对List<Map<String, Object>>集合排序
private void mySort(List<Map<String, Object>> list) { //list为待排序的集合,按SEQ字段排序 Comparator& ...
- 苹果审核不通过,程序/游戏不兼容IPV6网络
最近苹果升级的IOS10,所以那边网络环境变成IPV6,如果你的程序不兼容IPV6,苹果的程序会以这个不兼容的原因驳回审核. 那么如何让自己的程序兼容这个?方法其实C#本来已经提供给你的,而且很简单, ...
- Spring MVC使用ModelAndView进行重定向(转)
1.Servlet重定向forward与redirect: 使用servlet重定向有两种方式,一种是forward,另一种就是redirect.forward是服务器内部重定向,客户端并不知道服务器 ...
- 利用IE浏览器查看元素绑定的JS代码
- vsync信号产生与分发
以下分析基于android 4.4代码 vsync信号的产生.分发涉及到以下几个类,先主要了解下他们各自的功能: HWComposer:产生hardware vsync,post fb VSyncTh ...
- 视觉暂留-Info:这些神奇的“视觉暂留”动画,每一幅都让人拍案叫绝!
ylbtech-视觉暂留-Info:这些神奇的“视觉暂留”动画,每一幅都让人拍案叫绝! 1.返回顶部 1. 这些神奇的“视觉暂留”动画,每一幅都让人拍案叫绝! 原创|发布:2018-05-28 19: ...
- thrift python安装
http://thrift.apache.org/download/ tar -zxvf thrift-0.11.0.tar.gz cd thrift-0.11.0 ./configure --pre ...
- github中markdown语言的使用规则
开始使用github就接触了markdown,确实如它的宗旨所言"易读易写",语法简洁明了,功能比纯文本更强,是一种非常适用于网络的书写语言.并且一大优点是兼容HTML,只要不在m ...