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. 转,sql 50道练习题

    SQL语句50题   -- 一.创建教学系统的数据库,表,以及数据 --student(sno,sname,sage,ssex) 学生表--course(cno,cname,tno) 课程表--sc( ...

  2. 怎样运行jar包中的文件

    1. 2.编辑sysmodule.cmd文件 java -cp sysmodule.jar;classes12.jar;mysql-connector-java-5.0.3-bin.jar;jbcl. ...

  3. 二维bit模板

    #include<bits/stdc++.h> using namespace std; typedef long long ll; #define N 1100 const int mo ...

  4. 炸掉的fft,改天再调

    #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> ...

  5. 【免费】Linux命令行与Shell脚本编程大全 第3版 PDF全本 21MB 百度网盘下载

    2019年7月12日更新 链接: https://pan.baidu.com/s/17RDrepFf-GI427I7k3jBcQ 提取码: qk8k 网上的大部分都要积分什么的,很麻烦.这本很清晰,分 ...

  6. 鲁班学院java架构vip课程

    1.wps文档地址 https://docs.qq.com/doc/DRVNLUndvTmFSdEhO 2.百度网盘地址 https://pan.baidu.com/s/1uxaTzJZHKrsw_H ...

  7. ICEM-叶轮泵腔(2D转3D)

    原视频下载地址:https://yunpan.cn/cqUfdgMPzyr5y  访问密码 bb4f

  8. TortoiseGit的安装与配置

    1. 简介 TortoiseGit是Tortoise提供的Git版本可视化工具,简化Git记忆命令行的过程,将命令行可视化. 2. 下载 官网:https://tortoisegit.org/down ...

  9. Eclipse简明使用教程(java集成开发环境)

    说明:我使用的是绿色便携版的Eclipse,免安装,解压就能用.链接:https://download.csdn.net/download/loongstyle/10700321 1_Eclipse中 ...

  10. spring boot + vue 前后分离实现登录功能(一)

    使用webpack 打包初始化项目 vue init webpack book-vue 进入工程目录 cd hello-vue 安装 vue-router npm install vue-router ...