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 ;
}

csu 1756: Prime的更多相关文章

  1. 【CSU 1756】Prime

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1756 直接暴力O(n^2logn)过不了 两两算gcd 考虑每个数的范围[1,1000]统计一下即 ...

  2. CSU 1425 Prime Summation

    原题链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1425 DP题. f[i][j]表示当前数字为i,分解式中最大质数为j的方案数,那么,状态 ...

  3. csu 1756(数论+去重)

    Prime Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 84  Solved: 12[Submit][Status][Web Board] Descr ...

  4. CSU 1425 NUDT校赛 I题 Prime Summation

    这个题本来有希望在比赛里面出了的 当时也想着用递推 因为后面的数明显是由前面的推过来的 但是在计算的时候 因为判重的问题 ...很无语.我打算用一个tot[i]来存i的总种树,tot[i]+=tot[ ...

  5. 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 ...

  6. CSU 1552 Friends(二分图 + 米勒测试)

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1552 Description On an alien planet, every e ...

  7. Java 素数 prime numbers-LeetCode 204

    Description: Count the number of prime numbers less than a non-negative number, n click to show more ...

  8. Prime Generator

    Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate ...

  9. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

随机推荐

  1. icpc 银川 H. Delivery Route SPFA优化

    Problem Description Pony is the boss of a courier company. The company needs to deliver packages to ...

  2. luogu 3248

    直接向原树加子树是不可能的考虑重新建立这样一颗树,我们称之为 S 树 将每次需要添加的子树看做一个点,称之为 S 点 新建的树就是由这些点构成的,那么树的大小是合理的 初始节点为整棵原树由于添加的子树 ...

  3. Cogs 13. 运输问题4(费用流)

    运输问题4 ★★☆ 输入文件:maxflowd.in 输出文件:maxflowd.out 简单对比 时间限制:1 s 内存限制:128 MB [问题描述] 一个工厂每天生产若干商品,需运输到销售部门进 ...

  4. TensorFlow(九):卷积神经网络

    一:传统神经网络存在的问题 权值太多,计算量太大 权值太多,需要大量样本进行训练 二:卷积神经网络(CNN) CNN通过感受野和权值共享减少了神经网络需要训练的参数个数. 三:池化 四:卷积操作 五: ...

  5. NetworkX系列教程(10)-算法之一:最短路径问题

    小书匠Graph图论 重头戏部分来了,写到这里我感觉得仔细认真点了,可能在NetworkX中,实现某些算法就一句话的事,但是这个算法是做什么的,用在什么地方,原理是怎么样的,不清除,所以,我决定先把图 ...

  6. 视觉SLAM十四讲(三)——三维空间刚体运动(下)

    理论部分请看 :三维空间刚体运动 一.Eigen的使用 首先安装 Eigen: sudo apt-get install libeigen3-dev 一般都安装在 /usr/include/eigen ...

  7. spring + spring mvc 使用 maven 编译出现异常

    异常如下: [INFO] Scanning for projects...[INFO] [INFO] ------------------------------------------------- ...

  8. Linux中查看某个端口占用情况

    譬如在linux中排查某个端口是否被占用,可以通过如下命令进行排查,排查方法如下: 1: 排查 : 应用是否被人debug.  8787 为端口号 netstat -anp |grep 8787 图中 ...

  9. centos7 安装 Mysql 5.7.27,详细完整教程

    1. 下载 MySQL yum包 wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm   2.安装MySQL源 ...

  10. harukaの收藏夹

    #include<map> 比较好的图论作图网站 heap Sth About EXCRT OI-Wiki 数学 树形dp入门 开开心心学背包 一起复习qwq 模板库(非原创) LaTex ...