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: ...
随机推荐
- 【 USACO11JAN】 利润 【洛谷P3009】
P3009 [USACO11JAN]利润Profits 题目描述 The cows have opened a new business, and Farmer John wants to see h ...
- 第八章—BOM(一)
ECMAscript是JS的核心,而要在web上使用JS,那么BOM无疑是真正的核心.BOM叫浏览器对象模型,它提供了许多对象,用于访问浏览器的功能. BOM的核心对象是window,它表示浏览器的一 ...
- excel之VLOOKUP函数的使用
VLOOKUP 函数是excel中比较常用的一个函数.该函数具有有四个参数: 1.查找值:指本表中的值,需要根据本表中的某一值在本表或其他表中查找我们想要获取的值就称为查找值. 2.数据表:指查找的范 ...
- php require_once的使用方法
学习笔记 require_once 语句和 require 语句完全相同,唯一区别是 PHP 会检查该文件是否已经被包含过,如果是则不会再次包含. equire_once() 为了避免重复加载文件. ...
- python第一天 :计算机基础(一)
1.什么是编程语言 答:人类与计算机交流的介质 2.什么是编程 答:利用编程语言控制计算机解决问题 3.为什么要编程 答:可以控制计算机做事,提高生产生活效率 4.计算机的五大组成部分分别有什么作用? ...
- Vue项目根据不同运行环境打包项目
前提 项目是直接通过 vue-cli脚手架 生成的: 假设在项目开发中,分为三个环境 -- · 测试环境· 预生产环境· 生产环境 每个环境的接口地址都是不同的,而 vue-cli 给出的环境只有 d ...
- SQL优化系列(一)- 优化SQL
优化SQL SQL开发人员从源代码中发现一条跑得很慢的SQL, 如何优化? DBA从AWR报告中发现一条跑得很慢的SQL,没有源代码或者不想修改源代码怎么办? SQL自动优化工具SQL Tuning ...
- JQuery--动画和DOM的增删查改常用函数总结
jQuery的动画api animate jQuery设置动画 animate({属性集合},时间); animate({属性集合},时间,回调函数); animate({属性集合},时间,运动曲线, ...
- Mybatis自查询递归查找子菜单
之前写过 java从数据库读取菜单,递归生成菜单树 今天才发现mybatis也可以递归查询子菜单 先看一下数据库 主键id,名称name,父id,和url 设计菜单类 public class Men ...
- 【OI】位运算操作
一.基础操作 1.a<<b 将二进制a左移b位,不够的地方用0补位 例如 100<<2 == 10000 2.a>>b 将二进制a右移b位 例如 100>&g ...