Description

In mathematics, a square number is an integer that is the square of an integer. In other words, it is the product of some integer with itself. For example, 9 is a square number, since it can be written as 3 * 3.

Given an array of distinct integers (a1, a2, ..., an), you need to find the number of pairs (ai, aj) that satisfy (ai * aj) is a square number.

Input

The first line of the input contains an integer T (1 ≤ T ≤ 20) which means the number of test cases.

Then T lines follow, each line starts with a number N (1 ≤ N ≤ 100000), then N integers followed (all the integers are between 1 and 1000000).

Output

For each test case, you should output the answer of each case.

Sample Input

1
5
1 2 3 4 12

Sample Output

2

题意:

平方数:某个整数的平方;

给定一串整数(a1,a2........an),求有多少对整数的乘积(ai*aj),使得这个乘积为平方数。

题解:

唯一分解定理:任何一个大于1的自然数 N,如果N不为质数,那么N可以唯一分解成有限个质数的乘积

那么平方数肯定能分解成若干素数的偶次幂,先将每个质数的平方打表,将分解后剩余的部分存入数组中,最后两两配对。

代码:

#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <cstdlib>
using namespace std;
#define is_lower(c) (c>='a' && c<='z')
#define is_upper(c) (c>='A' && c<='Z')
#define is_alpha(c) (is_lower(c) || is_upper(c))
#define is_digit(c) (c>='0' && c<='9')
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define IO ios::sync_with_stdio(0);\
    cin.tie();\
    cout.tie();
#define For(i,a,b) for(int i = a; i <= b; i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
const ll inf=0x3f3f3f3f;
;
const ll inf_ll=(ll)1e18;
const ll mod=1000000007LL;
;
];
int prime[maxn],prime1[maxn];
];
];
;
void getprime()
{
    memset(vis, false, sizeof(vis));
    int N = sqrt(maxn);
    ; i <= N; ++i)
    {
        if ( !vis[i] )
        {
            prime[++num] = i;
            prime1[num] = i*i;
        }
        ; j <= num && i * prime[j] <= N ;  j++)
        {
            vis[ i  *  prime[j] ]  =  true;
            ) break;
        }
    }
}
int main()
{
    int T;
    cin>>T;
    getprime();
    while(T--)
    {
        int x;
        memset(cnt,,sizeof(cnt));
        cin>>x;
        For(i,,x)
        {
            int xx;
            cin>>xx;
            ; xx>=prime1[j]&&j<=num; j++)
            {
                )
                    xx/=prime1[j];
            }
            cnt[xx]++;
        }
        ll ans = ;
        For(i,,maxn-)
        if(cnt[i])
            ans+= cnt[i]*(cnt[i]-)/;
        cout<<ans<<endl;
    }
    ;
}

/***************************************************
User name: exist
Result: Accepted
Take time: 572ms
Take Memory: 2544KB
Submit time: 2018-03-17 13:55:51
****************************************************/

山东省第六届省赛 H题:Square Number的更多相关文章

  1. 山东省第七届省赛 D题:Swiss-system tournament(归并排序)

    Description A Swiss-system tournament is a tournament which uses a non-elimination format. The first ...

  2. Sdut 2164 Binomial Coeffcients (组合数学) (山东省ACM第二届省赛 D 题)

    Binomial Coeffcients TimeLimit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 输入 输出 示例输入 1 1 10 2 9 ...

  3. Sdut 2165 Crack Mathmen(数论)(山东省ACM第二届省赛E 题)

    Crack Mathmen TimeLimit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Since mathmen take security ...

  4. ACM Sdut 2158 Hello World!(数学题,排序) (山东省ACM第一届省赛C题)

    题目描述 We know thatIvan gives Saya three problems to solve (Problem F), and this is the firstproblem. ...

  5. 山东省第六届省赛 BIGZHUGOD and His Friends II(赛瓦定理)

    Description BIGZHUGOD and his three friends are playing a game in a triangle ground. The number of B ...

  6. 2013年省赛H题

    2013年省赛H题你不能每次都快速幂算A^x,优化就是预处理,把10^9预处理成10^5和10^4.想法真的是非常巧妙啊N=100000构造两个数组,f1[N],间隔为Af2[1e4]间隔为A^N,中 ...

  7. 湖南省第六届省赛题 Biggest Number (dfs+bfs,好题)

    Biggest Number 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 You have a maze with obstacles and non-zero di ...

  8. 山东省第六届ACM省赛

    A.Nias and Tug-of-War(sort排序) B.Lowest Unique Price(set+map) C.Game!(博弈) D.Stars E.BIGZHUGOD and His ...

  9. 山东省第六届ACM省赛 H---Square Number 【思考】

    题目描述 In mathematics, a square number is an integer that is the square of an integer. In other words, ...

随机推荐

  1. WebService使用介绍(二)

    Soap soap是什么 SOAP 是一种网络通信协议 SOAP即Simple Object Access Protocol简易对象访问协议 SOAP 用于跨平台应用程序之间的通信 SOAP 被设计用 ...

  2. [luogu2617]Dynamic Rankings

    题面在这里 description 动态区间第\(k\)大 data range \[n,m\le 10000,a_i,t\le 1e^9\] solution 前置技能:主席树,静态区间第\(k\) ...

  3. [Leetcode] set matrix zeroes 矩阵置零

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click ...

  4. BZOJ2001 [Hnoi2010]City 城市建设 【CDQ分治 + kruskal】

    题目链接 BZOJ2001 题解 CDQ分治神题... 难想难写.. 比较朴素的思想是对于每个询问都求一遍\(BST\),这样做显然会爆 考虑一下时间都浪费在了什么地方 我们每次求\(BST\)实际上 ...

  5. 插头dp题表

    bzoj1814: Ural 1519 Formula 1 bzoj3125: CITY bzoj1210: [HNOI2004]邮递员 bzoj2331: [SCOI2011]地板 bzoj1187 ...

  6. Spring源码解析-事件

    Spring事件的组件 主要是3个组件: 1.ApplicationEvent   事件 2.ApplicationListener 监听器,对事件进行监听 3.ApplicationEventMul ...

  7. HDU 2844 二进制优化的多重背包

    Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  8. [hihocoder 1050]求树的最长链

    题目链接:http://hihocoder.com/problemset/problem/1050 两种方法: 1. 两遍dfs,第一次随便找一个根,找到距离这个根最远的点,这个点必然是最长链的一端. ...

  9. 安卓sdk安装教程

    http://blog.csdn.net/love4399/article/details/77164500

  10. angular js的Inline Array Annotation的理解

    inline Array annotation的形式是: someModule.controller('MyController', ['$scope', 'greeter', function($s ...