1756: Prime

Submit Page   Summary   Time Limit: 3 Sec     Memory Limit: 128 Mb     Submitted: 281     Solved: 69


Description

如果a,b的最大公约数是1,说明a,b是一对互素的数,给定你n个数字,希望你找出互素的数的对数

Input

第一行输入一个正整数T,表示数据组数

每组数据第一行输入一个正整数n,表示数字的个数(n<=10000)

接下来一行输入n个正整数,每个数字大小不超过1000。

Output

输出互素的数的对数

Sample Input

1
4
10 9 6 35

Sample Output

3

Hint

Source

3901130321

 
 
题解:数字大小最大就是1000    开一个数组保存每一个数字出现的次数
然后从1开始枚举     判断1-2  1-3   1-4   ;;;1-999   1-1000    2-3    2-4 ;;;;n-1  -   n
是不是互素    如果是   就加上
 #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cstring>
#include <math.h> using namespace std;
int a,num[];
int gug(int x,int y)
{
if(x%y==)return y;
return gug(y,x%y);
}
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
for(int i=; i<; ++i)
{
num[i]=;
}
scanf("%d",&n);
for(int i=; i<n; ++i)
{
scanf("%d",&a);
num[a]++;
}
int ans=;
if(num[]>)ans+=num[]*(num[]-)/;
for(int i=; i<; ++i)
{
ans+=num[]*num[i];
for(int j=i+; j<=; ++j)
{
if((num[j]!=)&&(gug(j,i)==))
ans+=num[i]*num[j];
}
}
ans+=num[]*num[];
printf("%d\n",ans);
} return ;
}

最新文章

  1. Datatable常用系列一
  2. i7 4790 z97-ar ssd 固态硬盘 装机的一些经历
  3. MongoDB的TruncationException异常解决方法
  4. iOS——百度统计
  5. 【LAMP】在Debian系linux下安装LAMP
  6. ffdshow 源代码分析1 : 整体结构
  7. Find the largest multiple of 3 解答
  8. 九、 合成(Composite)模式 --结构模式(Structural Pattern)
  9. Android 反编译(一,apktool+smail2java)
  10. SPFILE 、PFILE 的全面解读
  11. putty 窗口管理
  12. tkinter第一章
  13. 20165304《JAVA程序设计》第二周学习总结
  14. 移动端web开发中对点透的处理,以及理解fastclick如何做到去除300ms延迟
  15. 吴恩达机器学习笔记56-多元高斯分布及其在误差检测中的应用(Multivariate Gaussian Distribution &amp; Anomaly Detection using the Multivariate Gaussian Distribution)
  16. WebRTC的视频解码原理简析
  17. Django框架详细介绍---ORM---图书信息系统专题训练
  18. IntelliJ快捷键笔记
  19. java里 equals和== 区别
  20. C#线程篇---线程池如何管理线程(6完结篇)

热门文章

  1. Laravel - 解决连接MySQL时报&quot;The server requested authentication method unknown to the client”错误
  2. PostgreSQL 进程结构
  3. P3802 小魔女帕琪 期望
  4. [MUTC2013]idiots
  5. 点击按钮切换内容效果(使用CSS DIV与JavaScript)
  6. 一个类中域(field)的首字母不要大写
  7. 对list某个条件排序,并实现分页
  8. python3 系统监控脚本(CPU,memory,网络,disk等)
  9. ibm 汇编
  10. 超轻量级虚拟终端sakura和tilda