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. hive,把一个表中计算好的数据,存到另一个外部表中

    直接上代码: 第一部分: case class OrdPacsresult_obj(pk_dcpv: String, result_obj: String) 第二部分: def ordsubj: Un ...

  2. KindEditor3.x-自动上传Word图片功能.

    Chrome+IE默认支持粘贴剪切板中的图片,但是我要发布的文章存在word里面,图片多达数十张,我总不能一张一张复制吧?Chrome高版本提供了可以将单张图片转换在BASE64字符串的功能.但是无法 ...

  3. leetcode解题报告(14):Max Consecutive Ones

    描述 Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: ...

  4. 【概率论】5-4:泊松分布(The Poisson Distribution)

    title: [概率论]5-4:泊松分布(The Poisson Distribution) categories: - Mathematic - Probability keywords: - Po ...

  5. 每秒浮点运算次数flops

    每秒浮点运算次数[编辑] 维基百科,自由的百科全书     跳到导航跳到搜索 此条目需要补充更多来源. (2018年2月28日)请协助添加多方面可靠来源以改善这篇条目,无法查证的内容可能会因为异议提出 ...

  6. EAST结构分析+pytorch源码实现

    目录 EAST结构分析+pytorch源码实现 @ 一. U-Net的前车之鉴 1.1 FCN网络结构 1.2 U-NET网络 1.3 CTPN网络 二. EAST结构分析 2.1 结构简述 2.2 ...

  7. grafana+mysql忘记admin密码解决方法

    通过mysql修改admin的密码. 我之前注册了一个用户,所以我直接复制lvusyy这个用户的密码即可. update user inner join (select password,salt,r ...

  8. LG5492 [PKUWC2018]随机算法

    题意 有一种贪心求最大独立集的算法: 随机一个排列 按顺序加入独立集,如果一个点能加入,就加入\({S}\) 给出一张图,问得出正确答案的概率. \(n \leq 20\) 传送门 思路 用 \(dp ...

  9. 微信小程序入门与实战 从0到1进行细致讲解 涵盖小程序开发核心技能下载

    第1章 什么是微信小程序? 第2章 小程序环境搭建与开发工具介绍 第3章 从一个简单的“欢迎“页面开始小程序之旅 第4章 第二个页面:新闻阅读列表 第5章 小程序的模板化与模块化 第6章 构建新闻详情 ...

  10. 2018-2019-2 20165234 《网络对抗技术》 Exp7 网络欺诈防范

    Exp7  网络欺诈防范 实验内容 1. 简单应用SET工具建立冒名网站 2. ettercap DNS spoof 3. 结合应用两种技术,用DNS spoof引导特定访问到冒名网站 4. 请勿使用 ...