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 ...
随机推荐
- How to Fix Broken Packages in Ubuntu
How to Fix Broken Packages in Ubuntu By Nick Congleton – Posted on Jan 11, 2019 in Linux Apt, Ubun ...
- xml介绍+xml创建+xml读取
1.xml介绍:(URL:https://blog.csdn.net/weixin_37861326/article/details/81082144) xml是用来传输内容的,是w3c推荐的 2.使 ...
- (4)打造简单OS-loader硬盘加载和C++写入文件
0.简要说明: 我们完全可以使用bochs创建映像文件,如https://blog.csdn.net/jadeshu/article/details/89046838 ,那么为什么还去用C++去模 ...
- <frame>、<iframe>、<embed>、<object> 和 <applet>
frame frame 必须在 frameset 里,而 frameset 又不能和 body 共存(就是一旦存在 frame,就不能存在 body 了,因此这个基本每人使用) 推荐阅读:https: ...
- codeforces#1251E2. Voting (Hard Version)(贪心)
题目链接: http://codeforces.com/contest/1251/problem/E2 题意: 主角需要获得n个人的投票 有两种方式让某个人投票 1,已经投票的人数大于m 2,花p枚硬 ...
- CentOS7 升级Python2.x到3.x
CentOS 7 中默认安装了 Python,版本比较低(2.7.5),为了使用新版 3.x,需要对旧版本进行升级.由于很多基本的命令.软件包都依赖旧版本,比如:yum.所以,在更新 Python 时 ...
- CodeForces - 1175D Array Splitting(数组划分+后缀和+贪心)
You are given an array a1,a2,…,ana1,a2,…,an and an integer kk. You are asked to divide this array in ...
- Windows平台下Java,tomcat安装与环境配置
问题描述:在Windows下面做Java web相关的项目的时候,Java和tomcat是基础,这里记载一下Java环境的配置以及tomcat的安装和配置. 使用工具:Windows.jdk安装包.t ...
- Cesium的Property机制总结
前言 Cesium官方教程中有一篇叫<空间数据可视化>(Visualizing Spatial Data).该文文末简单提到了Cesium的Property机制,然后话锋一转,宣告此教程的 ...
- qt QThread
QThread类提供了一个平台无关的方式来管理线程. 一个QThread对象在程序控制中管理一个线程.线程在run()中开始执行.默认情况下,run()通过调用exec()启动事件循环并在线程里运行一 ...