Sum Sum Sum

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

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
 
难点是把:primes[1]=1;
 
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std; const int MAXN = ;
bool flag[MAXN];
int primes[MAXN], pi;
void GetPrime_1()
{
int i, j;
pi = ;
memset(flag, false, sizeof(flag));
for (i = ; i < MAXN; i++)
if (!flag[i])
{
primes[i] = ;//素数标识为1
for (j = i; j < MAXN; j += i)
flag[j] = true;
}
} int main()
{
memset(primes,,sizeof(primes));
GetPrime_1();
primes[]=;
int n;
while(scanf("%d",&n)!=EOF)
{
long long ans=;
int a;
for(int i=;i<n;i++)
{
cin>>a;
if(primes[a]==)
ans+=a;
}
cout<<ans<<endl;
}
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. HDU 6058 - Kanade's sum | 2017 Multi-University Training Contest 3

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

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

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

  4. 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 ...

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

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

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

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

  7. Path Sum,Path Sum II

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

  8. [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 ...

  9. 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 ...

  10. 关于数论分块里r=sum/(sum/l)的证明!

    今天的模拟赛里T2要使用到数论分块,里面有一个重要的坎就是关于r=sum/(sum/l)的证明,网上关于这道题的题解里都没有关于这个的证明,那么我就来填补一下: 在以下的文章里,我都会使用lo(x)表 ...

随机推荐

  1. /touch滑屏事件

    //touch滑屏事件     var windowHeight = $(window).height(),     $body = $("body");     $body.cs ...

  2. window时间同步机制的简单介绍

    1 window自身现在采用w32tm程序来进行时间校正,window自身携带NTP程序,但默认下时关闭的,默认的NTP时客户端. 2 w32tm时用来代替早期的时钟同步程序net  time 3 w ...

  3. No.1 selenium学习之路之浏览器操作

    selenium基础,首先就是浏览器的相关操作 下面描述几种浏览器的常用操作 1.打开浏览器 webdriver后面添加想要打开的浏览器 Ie或者Chrome 2.打开指定页面(百度) 3.休眠时间 ...

  4. 10 个优质的 Laravel 扩展推荐

    这里有 10+ 个用来搭建 Laravel 应用的包 为何会创建这个包的列表?因为我是一个「比较懒」的开发者,在脸书上是多个 Laravel 小组的成员.平日遇到最多的问题就是开发是需要用那些包.我很 ...

  5. How to omit h1 title heading in HTML export

    How to omit h1 title heading in HTML export */--> Introduce how to omit h1 title in the exported ...

  6. 20165333 实验二 Java面向对象程序设计

    姓名:陈国超 学号:20165333 班级:1653 实验课程:JAVA程序设计 实验名称:Java面向对象程序设计 实验时间:2018.4.14 指导老师:娄家鹏 实验内容及步骤 (一) " ...

  7. ef查询mysql数据库数据支持DbFunctions函数

    1.缘由 快下班的时候,一同事说在写linq查询语句时where条件中写两时间相减大于某具体天数报错:后来仔细一问,经抽象简化,可以总结为下面的公式: a.当前时间 减去 某表时间字段 大于 某具体天 ...

  8. information that should help you find out what is causing the crash.

    091130 11:16:11 - mysqld got exception 0xc0000005 ; This could be because you hit a bug. It is also ...

  9. java8 - 3

    import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.functio ...

  10. Phoenix的安装使用与SQL查询HBase

    一. Phoenix的简介 1. 什么是phoenix 现有hbase的查询工具有很多如:Hive,Tez,Impala,Shark/Spark,Phoenix等.今天主要说Phoenix.phoen ...