CA Loves GCD
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.
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
2
2 4
3
1 2 3
10
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;
const int maxn = ;
const int mod = ;
typedef long long ll;
//priority_queue<int, vector<int>, greater<int> > pq;
int Gcd[maxn][maxn],dp[maxn][maxn];
int gcd(int a,int b){
return b == ?a:gcd(b,a%b);
}
void up(int &x){
if(x>=mod) x -= mod;
}
void pre(){
for(int i = ; i<=; i++)
for(int j = ; j<=; j++)
Gcd[i][j] = gcd(i,j);
}
void solve(){
int t,n;
pre();
scanf("%d",&t);
while(t--){
scanf("%d",&n);
memset(dp,,sizeof(dp));
dp[][] = ;
int x;
for(int i = ; i<n; i++){
scanf("%d",&x);
for(int j = ; j<=; j++)
if(dp[i][j]){
up(dp[i+][Gcd[j][x]] += dp[i][j]); up(dp[i+][j] += dp[i][j]%mod);
}
}
int sum = ;
for(int i = ; i<=; i++){
// if(dp[n][i]) printf("%d\n",dp[n+1][i]);
up(sum += ((ll)i*dp[n][i])%mod);
}
printf("%d\n",sum%mod);
}
}
int main()
{
solve();
return ;
}
卷珠帘
CA Loves 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: ...
- 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(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 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- hdu-5656 CA Loves GCD(dp+数论)
题目链接: CA Loves GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- hdu 5656 CA Loves GCD
CA Loves GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
随机推荐
- hdu 1212 Big Number(大数取模)
Problem Description As we know, Big Number is always troublesome. But it's really important in our A ...
- 使用TcpTrace小工具截获Web Service的SOAP报文
Web Service客户端对服务端进行调用时,请求和响应都使用SOAP报文进行通讯.在开发和测试时,常常查看SOAP报文的内容,以便进行分析和调试.TcpTrace是一款比较小巧的工具,可以让我们截 ...
- 自定义cell,根据数据源,要对cell的布局进行调整,没有实现调整的相应效果
自定义cell,用于两种显示情况,首次进来A种情况(主材页面),正确显示,然后切换B种情况(辅材情况),可以正确显示,但是当再次切换回A种情况(主材情况)的时候,主材cell不能正常显示了,遗留的B中 ...
- 理解Java String和String Pool
本文转载自: http://blog.sina.com.cn/s/blog_5203f6ce0100tiux.html 要理解 java中String的运作方式,必须明确一点:String是一个非可变 ...
- NaN(Not a Number)问题
Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contai ...
- Toolbar Painter 工具条制作
工具条制作工具(ToolBarPainter2013.exe),专为程序猿设计,界面开发必备.当用VC编程制作工具条时,需要为工具栏上每一个button添加图标,是一件极其繁琐的事情,该工具可利用已有 ...
- 扩展方法之ToDictionary()
Person类: public class Person { public int Id { set; get; } public string WorkNo { set; get; } public ...
- OpenGL-------状态机
状态机就是一种存在于理论中的机器,它具有以下的特点: 1. 它有记忆的能力,能够记住自己当前的状态. 2. 它可以接收输入,根据输入的内容和自己的状态,修改自己的状态,并且可以得到输出. 3. 当它进 ...
- Toy Storage POJ 2398
题目大意:和 TOY题意一样,但是需要对隔板从左到右进行排序,要求输出的是升序排列的含有i个玩具的方格数,以及i值. 题目思路:判断叉积,二分遍历 #include<iostream> # ...
- UVALive - 3942 Remember the Word
input 字符串s 1<=len(s)<=300000 n 1<=n<=4000 word1 word2 ... wordn 1<=len(wordi)<=10 ...