csu 1756: Prime
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
#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 ;
}
csu 1756: Prime的更多相关文章
- 【CSU 1756】Prime
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1756 直接暴力O(n^2logn)过不了 两两算gcd 考虑每个数的范围[1,1000]统计一下即 ...
- CSU 1425 Prime Summation
原题链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1425 DP题. f[i][j]表示当前数字为i,分解式中最大质数为j的方案数,那么,状态 ...
- csu 1756(数论+去重)
Prime Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 84 Solved: 12[Submit][Status][Web Board] Descr ...
- CSU 1425 NUDT校赛 I题 Prime Summation
这个题本来有希望在比赛里面出了的 当时也想着用递推 因为后面的数明显是由前面的推过来的 但是在计算的时候 因为判重的问题 ...很无语.我打算用一个tot[i]来存i的总种树,tot[i]+=tot[ ...
- CSU 2018年12月月赛 F(2218): Finding prime numbers
Description xrdog has a number set. There are 95 numbers in this set. They all have something in com ...
- CSU 1552 Friends(二分图 + 米勒测试)
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1552 Description On an alien planet, every e ...
- Java 素数 prime numbers-LeetCode 204
Description: Count the number of prime numbers less than a non-negative number, n click to show more ...
- Prime Generator
Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
随机推荐
- MongoDB 查看chunk块大小
使用mongo shell连到mongos执行命令:AllChunkInfo("dbname.cellname",true) 点击(此处)折叠或打开 AllChunkInfo = ...
- C++ 获取二维数组的一维长度
行长度: ]); 列长度: ][]); ]); int column = lines / row;
- [WEB安全]Weblogic漏洞总结
0x01 Weblogic简介 1.1 叙述 Weblogic是美国Oracle公司出品的一个应用服务器(application server),确切的说是一个基于Java EE架构的中间件,是用于开 ...
- 浅谈无旋treap(fhq_treap)
一.简介 无旋Treap(fhq_treap),是一种不用旋转的treap,其代码复杂度不高,应用范围广(能代替普通treap和splay的所有功能),是一种极其强大的平衡树. 无旋Treap是一个叫 ...
- $('#jyzjg').combobox('clear');
$('#jyzjg').combobox('clear'); alert($('#jyzjg').combobox("getValue" ...
- 迭代器Iterator、for循环遍历、泛型
java.util.Collection接口 是集合的最顶层的接口,定义了集合共性的方法 接口无法直接创建对象,使用多态的方式创建对象 Collection<集合中的数据类型(泛型)> c ...
- Linux中 mkdir 创建文件夹命令
语法 mkdir (选项)(参数) 选项 -Z:设置安全上下文,当使用SELinux时有效: -m<目标属性>或--mode<目标属性>建立目录的同时设置目录的权限: -p或- ...
- Flutter移动电商实战 --(44)详细页_首屏自定义Widget编写
把详细页的图片.标题.编号和价格形成一个单独的widget去引用 详情页的顶部单独封装个插件 在pages下面新建detials_page的文件件并在里面新建页面details_top_area.da ...
- cv相关博客文章
收藏些图像处理,机器学习,深度学习方面比较不错的文章,时常学习,复习和膜拜吧... 图像方面(传统CV): 1. SIFT特征 https://www.cnblogs.com/wangguchangq ...
- HADOOP回顾
1. hadoop 分为四大模块 common 其他组件的公共一来模块 HDFS 分布式模块提供高吞吐量的数据访问 mapreduce 分布式计算模块 yarn 作业调度和集群资源管理模块 2. 安 ...