How many tuples

TimeLimit: 10000ms  MemoryLimit:65536KB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description

Given m positive integer a[1],a[2]…a[m]. We run the following program (in C++):

const int MAXN = 20; int a[MAXN], m; int gcd(int a, int b) {return b ? gcd(b, a % b) : a;} long long cnt = 0; void gao(int cur, int g) { if (cur > m) { if (g == 1)++cnt; return; } for (int i = 1; i <= a[cur]; ++i) gao(cur + 1, g < 0 ? i : gcd(g, i)); } int main() { scanf("%d", &m); for (int i = 1; i <= m; ++i) scanf("%d", a + i); gao(1, -1); cout << cnt << endl; return 0; }

Here gcd is the Greatest Common Divisor, Obviously, the program above is to find the number of tuples (b[1], b[2], …, b[m]) such that:

(1) gcd(b[1], b[2], …, b[m])=1. (Here we define gcd(num)=num, that is: gcd(9)=9, gcd(2)=2)

(2) 1≤b[i]≤a[i]. (1≤i≤m, b[i] is an integer)

Now in this problem, the m and a[i] may be very large! So could you write one efficient program to find the answer? The answer may be too large. So you can just output the answer Mod 1,000,000,007.

Input

The first line of the input contains an integer T (T≤10,000), indicating the number of test cases.

Then T cases, for any case, only two lines.

The first line is one integer m(1≤m≤20).

The second line has m integers indicate a[1], a[2], …, a[m] (1≤a[i]≤100,000,000, 1≤i≤m).

The answer may be too large. So you can just output the answer Mod 1,000,000,007.

Output
For each test case, print a line containing the answer Mod 1,000,000,007.
SampleInput
3
2
5 5
2
10000 9873
2
1234 5678
SampleOutput
19
60026156
4261566
Submit
题目统计信息详细
总AC数0
通过人数0
尝试人数1
总提交量1
AC率0.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: