题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5656
题意:
解法:
//HDU 5656
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1050;
const int mod = 100000007;
int dp[maxn][maxn], a[maxn], n;///dp[i][j]表示在前i个数中,选出若干个数使得它们的gcd为j的方案数,
///于是只需要枚举第i+1个数是否被选中来转移就可以了
long long ans;
int gcd(int a, int b){
return b==0?a:gcd(b, a%b);
}
void update(int &x, long long y)
{
x += y;
if(x>=mod) x-=mod;
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
ans = 0;
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
for(int i = 0; i < n; i++){
for(int j = 0; j < maxn; j++){
if(dp[i][j]){//不加限制会T
(dp[i+1][j] += dp[i][j])%=mod;
(dp[i+1][gcd(j, a[i+1])] += dp[i][j])%=mod;
}
}
}
for(int i = 1; i < maxn; i++){
(ans += 1LL*i*dp[n][i]%mod)%=mod;
}
printf("%d\n", ans);
}
return 0;
}