Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <map>
- #include <algorithm>
- using namespace std;
- typedef long long ll;
- const int mod = 1000000007;
- int t;
- int n;
- map <int, int> M;
- int res;
- int toPower(int a, int p)
- {
- int r = 1;
- while (p) {
- if (p & 1) r = ll(r) * ll(a) % ll(mod);
- p >>= 1; a = ll(a) * ll(a) % ll(mod);
- }
- return r;
- }
- int main()
- {
- scanf("%d", &t);
- for (int tc = 1; tc <= t; tc++) {
- M.clear();
- scanf("%d", &n);
- while (n--) {
- int a; scanf("%d", &a);
- M[a]++;
- }
- res = 0;
- for (map <int, int>::iterator it = M.begin(); it != M.end(); it++) if (it->second) {
- int inv = toPower(it->first, mod - 2);
- int lft = it->first == inv? it->second / 2: M.count(inv)? M[inv]: 0;
- if (!lft) continue;
- int tk = min(it->second, lft);
- it->second -= tk; M[inv] -= tk; res += tk;
- }
- printf("Case #%d: %d\n", tc, res);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment