SDUT 3258 山东省第六届ACM程序设计大赛——H Square Number
来源:互联网 发布:eclipse java开发教程 编辑:程序博客网 时间:2024/06/06 07:21
Square Number
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
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
#include <bits/stdc++.h>#define LL long long#define MAX 1001000using namespace std;int a[MAX],flag[MAX];bool prim(int x){ for(int i=2;i*i<=x;i++) { if(x % i == 0) return false; } return true;}LL Judge(int x){ return x * (x-1) / 2;}int main(){ //freopen("in.txt","r",stdin); std::ios::sync_with_stdio(false); int T,n,b; int top = 0; for(int i=2;i*i<MAX;i++) { if(prim(i)) { a[top++] = i * i; } } cin>>T; while(T--) { memset(flag,0,sizeof(flag)); cin>>n; for(int i=0;i<n;i++) { cin>>b; for(int j=0;a[j]<=b && a[j];j++) { while(b % a[j] == 0) b /= a[j]; } flag[b]++; } LL ant = 0; for(int i=0;i<MAX;i++) { ant += Judge(flag[i]); } cout<<ant<<endl; } return 0;}
- SDUT 3258 山东省第六届ACM程序设计大赛——H Square Number
- SDUT 3258 Square Number(2015年山东省第六届ACM大学生程序设计竞赛)
- sdut 3258 (第六届山东省ACM省赛H题)
- sdut 3258 Square Number(山东声第六届ACM程序设计竞赛)
- 山东省第六届ACM大学生程序设计竞赛-Square Number(完全平方数)
- 山东省第六届ACM竞赛 山东理工SDUT3258 Square Number
- Greatest Number 山东省第一届ACM程序设计大赛
- “浪潮杯”山东省第6届acm省赛 sdut3258 Square Number sdut 3257 Cube Number
- 【第七届山东省ACM竞赛】Square Number
- 山东省ACM竞赛(2015)---H - Square Number
- SDUT 3262 Colorful Cupcakes (2015年山东省第六届ACM大学生程序设计竞赛)
- 山东省第四届ACM省赛题——Square Number(平方数的性质)
- SDUT 2151 Phone Number 2010年山东省第一届ACM大学生程序设计竞赛
- SDUT 2157 Greatest Number (二分) 2010年山东省第一届ACM大学生程序设计竞赛
- SDUT 2410 Mine Number 2012年山东省第三届ACM大学生程序设计竞赛题
- 山东省第八届acm大赛 F题 (SDUT 3898)
- 山东省第八届acm大赛 J题 (SDUT 3902)
- 山东省第八届acm大赛 G题 (SDUT 3899)
- 循环结构
- 习题3—45
- 开启andriod手机的adbd,进行无线adb调试
- php实现的mysql数据库连接最常用类
- c++primer 第五版 指向常量的指针和常量指针
- SDUT 3258 山东省第六届ACM程序设计大赛——H Square Number
- Learning C++ by Creating Games With UE4(15.05.21)(Chapter 11-4)Monster
- 牛腩操作系统--CSS学习
- Agent Ransack工具
- Hello World
- 关于图的邻接表存储建立方式及深度遍历的个人理解以及数据结构7.22的算法
- 文章标题
- PopupWindow弹出后屏幕其他部分变暗
- Message Queue 简介