Skip to content

Instantly share code, notes, and snippets.

@srivatsan-ramesh
Last active October 29, 2016 05:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srivatsan-ramesh/1ec315fee6e108f308cf8e2b1970a47a to your computer and use it in GitHub Desktop.
Save srivatsan-ramesh/1ec315fee6e108f308cf8e2b1970a47a to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#define M 750000
#define MOD 1000000007
int inp[M+1], dp[M+1];
int main() {
int t,n,sum;
scanf("%d", &t);
while(t--) {
sum = 0;
memset(inp, 0, sizeof(inp));
memset(dp, 0, sizeof(dp));
scanf("%d", &n);
for(int i = 0, j; i < n; ++i) {
scanf("%d", &j);
inp[j] = 1;
}
for(int i = 1; i <= M; ++i) {
if(inp[i]) {
dp[i] = (dp[i] + 1) % MOD;
sum = (sum + 1) % MOD;
for(int j = 2 * i; j <= M; j += i) {
if(inp[j]) {
dp[j] = (dp[j] + dp[i]) % MOD;
sum = (sum + dp[i]) % MOD;
}
}
}
}
printf("%d\n", sum);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment