题目描述

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. Uncaught Error: artDialog: Document types require more than xhtml1.0

    这需要声明html文档,加上如下声明就不会报错了! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

  2. Linq 基本操作

    在linq中排序方法有: OrderBy()  --对某列升序排序 ThenBy()    --某列升序后对另一列后续升序排序 OrderByDescending() --对某列降序排序 ThenBy ...

  3. SpringBoot整合Dubbo报错: java.lang.ClassCastException

    com.alibaba.dubbo.rpc.RpcException: Failed to invoke remote proxy method queryGoodsLimitPage to regi ...

  4. 记一次服务器inodes数报警的事件

    # df -i 执行以上命令,发现/上的 inodes 占用率为81%,于是开始处理. 首先找出哪个目录底下文件数最多: # cd / # for i in $(ls);do echo ${i} &a ...

  5. python系列二:python3基本数据类型

    #标准数据类型——number(数字)a, b, c = 1, 2.2, "hello"print(a, end = ", ")print(b, end = & ...

  6. 【原创】学习CGLIB动态代理中遇到的问题

    代码清单1 CGLIB动态代理 package wulj.proxy.cglibProxy; import java.lang.reflect.Method; import net.sf.cglib. ...

  7. Servlet 3.0 介绍

    1. 概述 注解代替 web.xml 配置文件 异步处理 对上传的支持 2. 注解代替 web.xml 配置文件 使用方法 在 Servlet 类上添加 @WebServlet(urlPatterns ...

  8. MySQL中Index Condition Pushdown(ICP)优化

    在MySQL 5.6开始支持的一种根据索引进行查询的优化方式.之前的MySQL数据库版本不支持ICP,当进行索引查询是,首先根据索引来查找记录,然后在根据WHERE条件来过滤记录.在支持ICP后,My ...

  9. 001-maven下载jar后缀为lastUpdated问题

    问题简述 Maven在下载仓库中找不到相应资源时,网络中断等,会生成一个.lastUpdated为后缀的文件.如果这个文件存在,那么即使换一个有资源的仓库后,Maven依然不会去下载新资源. 解决方案 ...

  10. Use Private Members from Base Class

    最近看了一段代码:在导出类中调用继承自基类的某个public函数,该函数中对基类中的private数据成员 进行了赋值并将结果打印.看到程序的运行结果后,顿时感觉自己之前(我之前的理解这里就不说明了) ...