csu 1756: Prime
2024-08-30 10:12:45
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 ;
}
最新文章
- Datatable常用系列一
- i7 4790 z97-ar ssd 固态硬盘 装机的一些经历
- MongoDB的TruncationException异常解决方法
- iOS——百度统计
- 【LAMP】在Debian系linux下安装LAMP
- ffdshow 源代码分析1 : 整体结构
- Find the largest multiple of 3 解答
- 九、 合成(Composite)模式 --结构模式(Structural Pattern)
- Android 反编译(一,apktool+smail2java)
- SPFILE 、PFILE 的全面解读
- putty 窗口管理
- tkinter第一章
- 20165304《JAVA程序设计》第二周学习总结
- 移动端web开发中对点透的处理,以及理解fastclick如何做到去除300ms延迟
- 吴恩达机器学习笔记56-多元高斯分布及其在误差检测中的应用(Multivariate Gaussian Distribution &; Anomaly Detection using the Multivariate Gaussian Distribution)
- WebRTC的视频解码原理简析
- Django框架详细介绍---ORM---图书信息系统专题训练
- IntelliJ快捷键笔记
- java里 equals和== 区别
- C#线程篇---线程池如何管理线程(6完结篇)
热门文章
- Laravel - 解决连接MySQL时报";The server requested authentication method unknown to the client”错误
- PostgreSQL 进程结构
- P3802 小魔女帕琪 期望
- [MUTC2013]idiots
- 点击按钮切换内容效果(使用CSS DIV与JavaScript)
- 一个类中域(field)的首字母不要大写
- 对list某个条件排序,并实现分页
- python3 系统监控脚本(CPU,memory,网络,disk等)
- ibm 汇编
- 超轻量级虚拟终端sakura和tilda