题目描述

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. Java-iBATIS

    1.是什么? 2010年迁移到了google code,并且改名为MyBatis.ibatis1.ibatis2.到了版本3就改名为mybatis. iBATIS的是一个持久层框架,它能够自动在 Ja ...

  2. python静态网页爬虫之xpath(简单的博客更新提醒功能)

    直接上代码: #!/usr/bin/env python3 #antuor:Alan #-*- coding: utf-8 -*- import requests from lxml import e ...

  3. http://localhost:8080请求用户名和密码。信息为:“XDB” 解决办法

    windows查看端口占用情况 cmd下 netstat -ano 查看端口和对应的服务 为2520 Oracle的服务 源博客: http://blog.163.com/jxguo_05/blog/ ...

  4. 索引笔记《一》Oracle中的索引详解

    一. ROWID的概念 存储了row在数据文件中的具体位置:64位 编码的数据,A-Z, a-z, 0-9, +, 和 /, row在数据块中的存储方式 SELECT ROWID, last_name ...

  5. (转)gethostbyname() -- 用域名或主机名获取IP地址

    struct hostent *gethostbyname(const char *name); 这个函数的传入值是域名或者主机名,例如"www.google.cn"等等.传出值, ...

  6. MySQL (时间)日期相减取天数

    select TO_DAYS(str_to_date('12/1/2001 12:00:00 AM','%m/%d/%Y')) -TO_DAYS(str_to_date('11/28/2001 12: ...

  7. 为什么要提倡"Design Pattern"呢? 开闭原则 系统设计时,注意对扩展开放,对修改闭合。

    [亲身经历] 无规矩不成方圆 设计模式 - 搜狗百科 https://baike.sogou.com/v123729.htm?fromTitle=设计模式 为什么要提倡"Design Pat ...

  8. es 中 for in for of

    arr=[11,22,33,44,55,66,77,88]for (const i in arr){ console.log(i) if (i===4){ console.log(arr[i]) }} ...

  9. 2014-08-28——移动端web开发,基本Meta标签

    1.<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scal ...

  10. Google 翻译如何获取 tk 参数值?

    1.首先获取 TKK 参数,这个参数可以在 https://translate.google.com 网页获取, src:TKK=eval('((function(){var a\x3d2089517 ...