G. Pairs

The pair in the land of 1000000007 is the pair of numbers a and b with the following relation: a × b = 1 (mod 1000000007). It is believed to be the sign of divine. Your task is to increase the number of happy marriages so you must find the maximum number of distinct pairs! Distinct pairs can not have the same number (with the same index). Pairs are different when the sets of their indices are different

Input

The first line contains the number of test cases T (T ≤ 5). The first line of each test case contains the size of population, n (1 ≤ n ≤ 30000). The following n lines contain the numbers ai (1 ≤ ai < 1000000007).

Output

For each test case output one line containing “Case #tc: num”, where tc is the number of the test case (starting from 1) and num is the maximum number of distinct pairs.

Examples

Input

1
5
1
1
1
2
500000004

Output

Case #1: 2

题意:

有n个数,只有满足a×b%1000000007=1a\times b \% 1000000007 = 1的两个数可以凑成一对,每个数只能属于一个对,最多能组多少对
输入每个数0<ai<10000000070<a_i<1000000007

解:

移项可得

a×b%1000000007=1a=b1a=inv(b) a\times b \%1000000007 =1 \\ a=b^{-1} \\ a=inv(b)

只要两个数互为逆元即可,用map统计所有数的数量,对于每个数都看有几个数是它的逆元

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<map>
using namespace std;
typedef long long LL;
const LL mod = 1000000007;
LL quick_mod(LL a, LL b)
{
LL base = a;
LL ans = 1;
while (b)
{
if (b & 1)
{
ans *= base;
ans %= mod;
}
base *= base;
base %= mod;
b >>= 1;
}
return ans % mod;
}
LL a[100000];
map<LL, LL>mp;
int main()
{
int T;
scanf("%d", &T);
for (int tc = 1; tc <= T; tc++)
{
int n;
mp.clear();
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%lld", &a[i]);
mp[a[i]]++;
}
LL ans = 0;
for (int i = 0; i < n; i++)
{
LL inv = quick_mod(a[i], mod - 2) % mod;
if (inv == 1)
{
ans += mp[a[i]] / 2;
mp[a[i]] = 0;
}
else
{
int t = min(mp[a[i]], mp[inv]);
ans += t;
mp[a[i]] -= t;
mp[inv] -= t;
}
}
printf("Case #%d: %lld\n", tc, ans);
}
}