Sum Sum Sum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1033    Accepted Submission(s): 612

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
 
题意:一个数如果与小于等于它的非负整数的最大公约数是1,那么他就是P-number,给出一个子序列,问里面的P-number之和.
题解:注意不仅仅是素数,1也是P-number
  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<string.h>
  4. #include <stdlib.h>
  5. #include<math.h>
  6. #include<algorithm>
  7. using namespace std;
  8. typedef long long LL;
  9. const int N = ;
  10. int p[N];
  11. void init(){
  12. for(int i=;i<=;i++){
  13. if(!p[i]){
  14. for(int j=i*i;j<=;j+=i){
  15. p[j] = true;
  16. }
  17. }
  18. }
  19.  
  20. }
  21. int main()
  22. {
  23. init();
  24. int n;
  25. while(scanf("%d",&n)!=EOF){
  26. int sum = ;
  27. for(int i=;i<=n;i++){
  28. int v;
  29. scanf("%d",&v);
  30. if(!p[v]) sum+=v;
  31. }
  32. printf("%d\n",sum);
  33. }
  34. return ;
  35. }

hdu 5150(水题)的更多相关文章

  1. HDU-1042-N!(Java大法好 &amp;&amp; HDU大数水题)

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Subm ...

  2. HDU 5391 水题。

    E - 5 Time Limit:1500MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  3. hdu 1544 水题

    水题 /* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #i ...

  4. HDU排序水题

    1040水题; These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fa ...

  5. hdu 2710 水题

    题意:判断一些数里有最大因子的数 水题,省赛即将临近,高效的代码风格需要养成,为了简化代码,以后可能会更多的使用宏定义,但是通常也只是快速拿下第一道水题,涨自信.大部分的代码还是普通的形式,实际上能简 ...

  6. Dijkstra算法---HDU 2544 水题(模板)

    /* 对于只会弗洛伊德的我,迪杰斯特拉有点不是很理解,后来发现这主要用于单源最短路,稍稍明白了点,不过还是很菜,这里只是用了邻接矩阵 套模板,对于邻接表暂时还,,,没做题,后续再更新.现将这题贴上,应 ...

  7. hdu 5162(水题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5162 题解:看了半天以为测试用例写错了.这题玩文字游戏.它问的是当前第i名是原数组中的第几个. #i ...

  8. hdu 3357 水题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3357 #include <cstdio> #include <cmath> # ...

  9. hdu 5038 水题 可是题意坑

    http://acm.hdu.edu.cn/showproblem.php?pid=5038 就是求个众数  这个范围小 所以一个数组存是否存在的状态即可了 可是这句话真恶心  If not all ...

随机推荐

  1. Servlet过滤器---登录权限控制

    实现了登录时权限控制:进入首页.登录页以及登录servlet时,不用验证权限:进入其它页面时,须验证是否登录,未登录则跳转到登录页. 一个简单的首页:index.jsp <%@ page lan ...

  2. Java-JNA使用心得

    自上个月20号,历时整整一个月,终于找到工作入职了. 然后这段时间一直看公司的框架还有业务方面的东西.其实由于给分配了一个研究Java调用C语言接口的问题,导致框架业务方面的东西还不熟,然后现在手上又 ...

  3. JWT应用

    调试器库简介问一件T恤! 精心制作 JSON Web令牌简介 新:免费获得JWT手册并深入学习JWT! 什么是JSON Web Token? JSON Web Token(JWT)是一个开放标准(RF ...

  4. codility

    // you can also use imports, for example: // import java.util.*; // you can write to stdout for debu ...

  5. (原)C sharp杂谈记事(一)

    题记)最是那一低头的温柔,像一朵睡莲花不胜凉风的娇羞 1)接收 公司的X部门有个APP小项目,APP后台是C sharp的MVC,提供了一个C sharp的web from做管理员操作的后台操作,此项 ...

  6. Windows下安装PHP及开发环境配置

    一.Apache 因为Apache官网只提供源代码,如果要使用必须得自己编译,这里我选择第三方安装包Apache Lounge. 1. 进入Apachelounge官方下载地址:http://www. ...

  7. 转: jsp之c标签

    http://www.gbsou.com/2009/10/12/1028.htmljsp标签之c标签 核心标签库 它是JSTL中的核心库,为日常任务提供通用支持,如显示和设置变量.重复使用一组项目.测 ...

  8. fragment中的WebView返回上一页

    public final class Text1Fm extends Fragment { static WebView mWeb; private View mContentView; privat ...

  9. Thymeleaf 模板 在spring boot 中的引用和应用

    Thymeleaf是一个java类库,他是一个xml/xhtml/html5的模板引擎和Struts框架的freemarker模板类似,可以作为mvc的web应用的view层. Thymeleaf还提 ...

  10. PHP文件操作函数及文件指针理解

    知识点: 一.fopen(),文件打开函数,读写参数有: 1.R  : 只读,指针在文件开头 2.r+:读写,指针同上 3.W :只写,写入前会删除文件内容,然后指针回到文件开头,文件不存在则创建 4 ...