zoukankan      html  css  js  c++  java
  • BestCoder24 1001.Sum Sum Sum(hdu 5150) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5150

    题目意思:就是直接求素数。

      不过 n = 1,也属于答案范围!!只能说,一失足成千古恨啊~~~~~

      

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 using namespace std;
     6 
     7 const int maxn = 1000 + 5;
     8 int prime[maxn];
     9 
    10 bool is_prime(int x)
    11 {  
    12 //  if (x == 1)          // 太多手了,不能先入为主啊
    13 //   return false;       // 被人 hack 的罪魁祸首
    14     if (x == 2)
    15         return true;
    16     for (int i = 2; i * i <= x; i++)
    17     {
    18         if (x % i == 0)
    19             return false;
    20     }
    21     return true;
    22 }
    23 
    24 int main()
    25 {
    26     memset(prime, 0, sizeof(prime));
    27     for (int i = 1; i <= maxn; i++)
    28     {
    29         if (is_prime(i))
    30             prime[i] = 1;
    31     }
    32 
    33     int n, data;
    34     while(scanf("%d", &n) != EOF)
    35     {
    36         int sum = 0;
    37         for (int i = 0; i < n; i++)
    38         {
    39             scanf("%d", &data);
    40             if (prime[data])
    41                 sum += data;
    42         }
    43         printf("%d
    ", sum);
    44     }
    45     return 0;
    46 }
  • 相关阅读:
    POJ 1300 Open Door
    POJ 2230 Watchcow
    codevs 1028 花店橱窗布置
    codevs 1021 玛丽卡
    codevs 1519 过路费
    codevs 3287 货车运输
    codevs 3305 水果姐逛水果街二
    codevs 1036 商务旅行
    codevs 4605 LCA
    POJ 1330 Nearest Common Ancestors
  • 原文地址:https://www.cnblogs.com/windysai/p/4189193.html
Copyright © 2011-2022 走看看