Sum Sum Sum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
We call a positive number X P-number if there is not a positive number that is less than X and the greatest common divisor of these two numbers is bigger than 1.
Now you are given a sequence of integers. You task is to calculate the sum of P-numbers of the sequence.
 
Input
There are several test cases. 
In each test case:
The first line contains a integer N(1≤N≤1000). The second line contains N integers. Each integer is between 1 and 1000.
 
Output
For each test case, output the sum of P-numbers of the sequence.
 
Sample Input
3
5 6 7
1
10
 
Sample Output
12
0
 
Source

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=1e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
int prime(int n)
{
if(n<=)
return ;
if(n==)
return ;
if(n%==)
return ;
int k, upperBound=n/;
for(k=; k<=upperBound; k+=)
{
upperBound=n/k;
if(n%k==)
return ;
}
return ;
}
int flag[];
int main()
{
int n,x;
for(int i=;i<=;i++)
flag[i]=prime(i);
flag[]=;
while(~scanf("%d",&n))
{
int ans=;
for(int i=;i<=n;i++)
{
scanf("%d",&x);
if(flag[x])
ans+=x;
}
printf("%d\n",ans);
}
return ;
}

hdu 5150 Sum Sum Sum 水的更多相关文章

  1. hdu 1166 线段树(sum+单点修改)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  2. HDU5053the Sum of Cube(水题)

    HDU5053the Sum of Cube(水题) 题目链接 题目大意:给你L到N的范围,要求你求这个范围内的全部整数的立方和. 解题思路:注意不要用int的数相乘赋值给longlong的数,会溢出 ...

  3. HDU 6058 - Kanade's sum | 2017 Multi-University Training Contest 3

    /* HDU 6058 - Kanade's sum [ 思维,链表 ] | 2017 Multi-University Training Contest 3 题意: 给出排列 a[N],求所有区间的 ...

  4. HDU 1003:Max Sum(DP,连续子段和)

    Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  5. 32. Path Sum && Path Sum II

    Path Sum OJ: https://oj.leetcode.com/problems/path-sum/ Given a binary tree and a sum, determine if ...

  6. 有两个数组a,b,大小都为n;通过交换a,b中的元素,使sum(a)-sum(b)最小。

    今天在浏览网页的时候,发现了一个叫做  华为面试题(8分钟写出代码) 的链接,不确定真实性,纯属好奇,就点进去看看 这个可能是很老的题目吧,因为我看到这题目时,底下有好多评论了.提到XX排序,内存占用 ...

  7. 有两个数组a,b,大小都为n,;通过交换a,b中的元素,使sum(a)-sum(b)最小。

    有两个数组a,b,大小都为n,数组元素的值任意整形数,无序: 要求:通过交换a,b中的元素,使数组a元素的和与数组b元素的和之间的差最小. 当前数组a和数组b的和之差为    A = sum(a) - ...

  8. Path Sum,Path Sum II

    Path Sum Total Accepted: 81706 Total Submissions: 269391 Difficulty: Easy Given a binary tree and a ...

  9. [Count the numbers satisfying (m + sum(m) + sum(sum(m))) equals to N]

    Given an integer N, the task is to find out the count of numbers M that satisfy the condition M + su ...

  10. LeetCode之“树”:Path Sum && Path Sum II

    Path Sum 题目链接 题目要求: Given a binary tree and a sum, determine if the tree has a root-to-leaf path suc ...

随机推荐

  1. javaWeb 使用 jsp 和 javaBean 实现计算器功能

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  2. sqlite3把字段为int32(用c++的time(nullptr)获取的)的秒数显示为年月日时分秒

    select id, type, msg, datetime(updateTime, 'unixepoch', 'localtime') from ServerLog

  3. master-slave(主/从)模式

    主从模式 一般来说用在数据库集群比较多,主要是实现读写分离.对于数据库应用而言基本上是读大于写,因此由 Master 服务器负责增.删.改操作,由 Slave 负责读操作(也就是 SELECT),Ma ...

  4. java利用zxing编码解码一维码与二维码

    最近琢磨了一下二维码.一维码的编码.解码方法,感觉google的zxing用起来还是比较方便. 本人原创,欢迎转载,转载请标注原文地址:http://wallimn.iteye.com/blog/20 ...

  5. 2>&1 的用法说明

    经常关注linux脚本的人,一定看到过 2>&1 这样的用法,最初一定不明白其中的含义以及为什么是这样的一种组合.昨天偶然间再次看到了这个 2>&1 的写法,遂下决心搞明白 ...

  6. HDU 2222:Keywords Search(AC自动机模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=2222 KMP是单模式串匹配的算法,而AC自动机是用于多模式串匹配的算法.主要由Trie和KMP的思想构成. 题意 ...

  7. linkbutton datagrid showdialog 行效果

    protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e) { ListItemType itemTy ...

  8. tomcat清除缓存

    方案一:点击进入解压后的tomcat,找到work文件夹,.此文件下有个catalina目录(tomcat小名叫catalina),work目录下的文件都可以删除.如果我们先前发布的一个项目有错,大家 ...

  9. I love sneakers!(分组背包HDU3033)

    I love sneakers! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  10. Socket状态变迁图

    在一些防火墙或端口管理工具中经常会看到连接状态为CLOSED CLOSE_WITE LAST_ACK等的进程, 虽然状态就那么很少的几个, 而且看字面意思也能猜个大概, 但没做过Socket编程的朋友 ...