题目描述

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. ios -过滤字符串特殊字符

    //过滤 " [ ] " + (NSString *)onTwoCommseparatedWithString:(NSString *)string { //过滤 " [ ...

  2. python3 - 使用__slots__限制实例属性

    为了限制实例的属性,可以在定义class的时候,定义一个特殊的__slots__变量,来限制class实例能添加的属性.比如,只允许对Persion实例添加name 和 age 属性 class Pe ...

  3. 使用PHP创建一个socket服务端

    与常规web开发不同,使用socket开发可以摆脱http的限制.可自定义协议,使用长连接.PHP代码常驻内存等.学习资料来源于workerman官方视频与文档. 通常创建一个socket服务包括这几 ...

  4. poj 3590(dp 置换)

    题目的意思是对于序列1,2,...,n.要你给出一种字典序最小的置换使得经过X次后变成最初状态,且要求最小的X最大. 通过理解置换的性质,问题可以等价于求x1,x2,..,xn 使得x1+x2+... ...

  5. ASP.NET通过代码给TextBox添加事件(点击显示日历)

    private void BindDate() { tbApplyStartDate.Attributes.Add("onclick", "new Calendar(). ...

  6. iOS响应超出View范围点击事件

    // 在view中重写以下方法,其中self.button就是那个希望被触发点击事件的按钮 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent ...

  7. urlencode rawurlencode htmlspecialchars htmlentities

    w string urlencode ( string $str ) 返回字符串,此字符串中除了 -_. 之外的所有非字母数字字符都将被替换成百分号(%)后跟两位十六进制数,空格则编码为加号(+).此 ...

  8. Linux三剑客之老二-------sed命令详解

    sed命令 文件 编辑 本文索引 [隐藏] sed的选项.命令.替换标记 选项 参数 sed命令 sed替换标记 sed元字符集 sed用法实例 替换操作:s命令 全面替换标记g 定界符 删除操作:d ...

  9. make编译二

    GNU 的 make 很强大, 它可以自动推导文件以及文件依赖关系后面的命令,于是我们就没必要去在每一个[.o]文件后都写上类似的命令,因为,我们的 make 会自动识别,并自己推导命令 只要 mak ...

  10. 021-Spring Boot 测试,Junit方式使用,mock方式,Controller测试

    一.概述 二.Junit方式使用 2.1.基本使用 eclipse在新建的类上,右键→new→Junit Test Case,修改一下Source folder,选择src/test/java,下一步 ...