题目描述

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.
 

输入

 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).
 

输出

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

示例输入

1
5
1 2 3 4 12

示例输出

2

题目:每组给你n个数,问这n这数中存在多少对这样的(ai, aj), ai*aj的乘机是一个完全平方数。输出对数。 任何一个整数n都可以这样表示: n=(p^2)*k; p是一个素数或者是1
例如n=1 2 3的时候可以表示成:1=(1^2)*1; 2=(1^2)*2; 3=(1^2)*3; a1=(p^2)*k1; a2=(q^2)*k2;
if(k1==k2){
  a1*a2的积一定是一个完全平方数
}//原理 code:
#include <stdio.h>
#include <string.h> bool prime(int x)
{
for(int i=2; i*i<=x; i++){
if(x%i==0) return false;
}
return true; //判断素数
} int a[1000], cnt[1000000+10]; int main()
{
//将100万以内的"素数的完全平方数"打表
int e=0;
for(int i=2; i*i<=1000000; i++){
if(prime(i))
a[e++]=i*i;
}
int tg; scanf("%d", &tg);
int n, i, j;
while(tg--)
{
scanf("%d", &n);
int dd;
int mm=1;
memset(cnt,0,sizeof(cnt));
while(n--){
scanf("%d", &dd);
for(i=0; i<e&&a[i]<=dd; i++){
while(dd%a[i]==0)
dd/=a[i];
}
if(dd>mm) mm=dd;
cnt[dd]++;
}
long long ans=0;
for(j=1; j<=mm; j++){
ans+=(cnt[j]*(cnt[j]-1)/2);
}
printf("%lld\n", ans);
}
}


山东省第六届ACM省赛 H---Square Number 【思考】的更多相关文章

  1. 山东省第六届ACM省赛

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

  2. 山东省第七届ACM省赛------Memory Leak

    Memory Leak Time Limit: 2000MS Memory limit: 131072K 题目描述 Memory Leak is a well-known kind of bug in ...

  3. 山东省第七届ACM省赛------Reversed Words

    Reversed Words Time Limit: 2000MS Memory limit: 131072K 题目描述 Some aliens are learning English. They ...

  4. 山东省第七届ACM省赛------Triple Nim

    Triple Nim Time Limit: 2000MS Memory limit: 65536K 题目描述 Alice and Bob are always playing all kinds o ...

  5. 山东省第七届ACM省赛------The Binding of Isaac

    The Binding of Isaac Time Limit: 2000MS Memory limit: 65536K 题目描述 Ok, now I will introduce this game ...

  6. 山东省第七届ACM省赛------Fibonacci

    Fibonacci Time Limit: 2000MS Memory limit: 131072K 题目描述 Fibonacci numbers are well-known as follow: ...

  7. 山东省第七届ACM省赛------Julyed

    Julyed Time Limit: 2000MS Memory limit: 65536K 题目描述 Julyed is preparing for her CET-6. She has N wor ...

  8. 第六届acm省赛总结(退役贴)

    前言: 这是我的退役贴,之前发到了空间里,突然想到也要在博客里发一篇,虽然我很弱,但是要离开了还是有些感触,写出来和大家分享一下,希望不要见笑.回来看看,这里也好久没有更新了,这一年确实有些懈怠,解题 ...

  9. 山东省第十届ACM省赛参赛后的学期总结

    5.11,5.12两天的济南之旅结束了,我也参加了人生中第一次正式的acm比赛,虽然是以友情队的身份,但是我依旧十分兴奋. 其实一直想写博客来增加自己的能力的,但是一直拖到现在,正赶上老师要求写一份总 ...

随机推荐

  1. 不通过AppStore,在iOS设备上直接安装应用程序的原理

    本文转载至  http://mobile.51cto.com/hot-439095.htm 通过itms-services协议,可以通过safari浏览器直接在iOS设备上安装应用程序.利用这种方式, ...

  2. [Spring Data MongoDB]学习笔记--MongoTemplate查询操作

    查询操作主要用到两个类:Query, Criteria 所有的find方法都需要一个query的object. 1. 直接通过json来查找,不过这种方式在代码中是不推荐的. BasicQuery q ...

  3. vs报错找不到错在哪里!Validation failed for one or more entities

    今天在处理Entity Framework修改数据库时,报错: Validation failed for one or more entities. See 'EntityValidationErr ...

  4. 关东升的《从零开始学Swift》即将出版

    大家好: 苹果2015WWDC大会发布了Swift2.0,它较之前的版本Swift1.x有很大的变化,所以我即将出版<从零开始学Swift> <从零开始学Swift>将在< ...

  5. android菜鸟学习笔记27----Fragment的简单使用

    1.Fragment的生命周期: 简单在新建一个MyFragment继承自Fragment,重写各个生命周期回调方法,各个方法中直接输出标识相关函数被调用的信息. 重写MainActivity的各个生 ...

  6. influxDB选择类函数

    1)TOP()函数 作用:返回一个字段中最大的N个值,字段类型必须是长整型或float64类型. 语法: SELECT TOP(<field_key>[,<tag_keys>] ...

  7. 巨蟒python全栈开发linux之centos2

    1.一些命令回顾 在vm中,右击"打开终端",输入命令ifconfig,得到的下图算是一个终端,并且我们可以看到服务器的ip是192.168.34.128 我们通过windows上 ...

  8. 解决IIS部署网站引用woff/woff2/svg字体报404错误

    一.问题 在IIS上部署网站,网页引用woff字体时,浏览器报“找不到woff.woff2字体”.“404”错误,不仅预设的字体加载不出来,还影响网页加载速度. 二.原因 IIS默认设置情况下不识别. ...

  9. Python3.6全栈开发实例[004]

    4.计算传入函数的字符串中, 数字.字母.空格以及其他内容的个数,并返回结果. s1 = 'wan%$#(gwdwq\nwdhuaiww3 w02041718' def func1(s1): dic ...

  10. Python3.6全栈开发实例[018]

    18.车牌区域划分, 现给出以下车牌.根据车牌的信息, 分析出各省的车牌持有量.(升级题) result = {} for car in cars: location = locals[car[0]] ...