Test instructions
T Group data:
n digits, whichever is the gcd of all combinations of 1-n numbers
Idea: DP
/*
DP[I][J] Indicates the number of all methods gcd=j with the first I number.
Dp[i + 1][GCD (j,a[i + 1])] + + dp[i][j];
Dp[i + 1][j] + = dp[i][j];
*/
1#include <cstdio>2#include <cstring>3#include <cstring>4 5#include <algorithm>6#include <Set>7#include <map>8#include <vector>9#include <stack>Ten#include <string> One#include <cmath> A -#include <iostream> - #defineRep (i,n) for (int (i) =0; (i) < (int) (n); + + (i)) the #defineAll (o) (o). Begin (), (O). End () - #defineMEM (o) memset (o), 0,sizeof ((o)); - #defineMEML (o) memset ((O), 0x7f7f7f7f,sizeof ((o))); - using namespacestd; +typedefLong Longll; - Const DoublePI = ACOs (-1.0); + Const intMOD =100000007; A at intgcd[1005][1005]; - inta[1005]; -ll dp[1005][1005]; - intgcdintCanintBB) { - returnBB = =0? AA:GCD (bb,aa%BB); - } in voidinit () { -Rep (I,1002){ toRep (J,1002){ +GCD[I][J] =gcd (i,j); - } the } * $ }Panax Notoginseng /* - Dp[i][j] Indicates the number of all methods gcd=j with the first I number. the + dp[i + 1][GCD (j,a[i + 1])] + + dp[i][j]; A Dp[i + 1][j] + = dp[i][j]; the */ + intMain () { - $ intT,n; $ init (); -scanf"%d",&T); - while(t--){ thescanf"%d",&n); - intMaxA =0;Wuyi Rep (i,n) { thescanf"%d",&a[i]); -MaxA =Max (A[I],MAXA); Wu } - Mem (DP); Aboutdp[0][0] =1; $ Rep (i,n) { -Rep (J, (maxa+1)){ -dp[i+1][J] = (dp[i+1][J] + dp[i][j])%MOD; -dp[i+1[Gcd[a[i]][j]] = (Dp[i][j] + dp[i+1[Gcd[a[i]][j]])%MOD; A } + } thell res =0; - for(inti =0; I <=1002; i + +){ $Res = (res + (dp[n][i]*i)%mod)%MOD; the } theprintf"%lld\n", res); the } the - in return 0; the}
HDU 5656 CA Loves GCD (DP)