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 ...
随机推荐
- 经典.net面试题目(3)
1. asp.net中web应用程序获取数据的流程: A.Web Page B.Fill C.Sql05 D.Data Sourse E.DataGrid F.DataSet G.Selec ...
- httpclient调用方法
/** * GET请求 * * @param url * 请求url,参数拼在请求串中 */ public static String get(String url) ...
- VG、LV、rezise2fs、lvresize、fuer使用说明
南沙节点改变LV大小,参考鸟哥第 570页 1.# resize2fs /dev/mapper/vg_niotsvr3-lv_home 150G resize2fs 1.41.12 (17-May-2 ...
- Boost的VS开发环境搭建
1. 下载并解压Boost C++ Libs 下载地址: SourceForge:http://sourceforge.net/projects/boost/files/boost/1.48.0/ B ...
- nuget pack 时不包含依赖包(而不是引用项目的dll,区别于IncludeReferencedProjects)
Excluding development dependencies when creating packages Some NuGet packages are useful as developm ...
- centos mono
wget http://download.mono-project.com/sources/mono/mono-4.0.1.tar.bz2wget http://download.mono-proje ...
- C# Socket的TCP通讯
Socket的TCP通讯 一. socket的通讯原理 服务器端的步骤如下. (1)建立服务器端的Socket,开始侦听整个网络中的连接请求. (2)当检测到来自客户端的连接请求时,向客户端发送收到连 ...
- 在DLL中导出另一静态库中的函数
开发环境: win7_x64.VS2013 应用场景: 动态库A依赖动态库B,而动态库B又使用了静态库C:有些情况下,我们需要将C从B里面导出,然后提供给A使用. 正文: Step1: 1.新建测试静 ...
- 移动Web框架:jQuery Mobile VS Sencha Touch
最近常被问到是用 jQuery Mobile还是Sencha Touch,本人也比较关注这两个框架,试图从以下两方面发表点儿见解: 身家背景,都系出名门 1.jQuery Mobile 建立在jQue ...
- ios学习基础篇一
搜集的不错的oc学习资料 大概总结: http://my.oschina.net/luoguankun/blog/208526 详细教程: http://www.w3cschool.cc/ios/io ...