zoukankan      html  css  js  c++  java
  • HDU 5150 Sum Sum Sum 素数

    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(1N1000). 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 = 1001;
    bool flag[MAXN];
    int primes[MAXN], pi;
    void GetPrime_1()
    {
        int i, j;
        pi = 0;
        memset(flag, false, sizeof(flag));
        for (i = 2; i < MAXN; i++)
            if (!flag[i])
            {
                primes[i] = 1;//素数标识为1
                for (j = i; j < MAXN; j += i)
                    flag[j] = true;
            }
    }
    
    int main()
    {
        memset(primes,0,sizeof(primes));
        GetPrime_1();
        primes[1]=1;
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            long long ans=0;
            int a;
            for(int i=0;i<n;i++)
            {
                cin>>a;
                if(primes[a]==1)
                    ans+=a;
            }
            cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    将一张图片的人物融入另一张图片中
    填充---内容识别图片
    使用蒙版--渐变--制作瓶子倒影
    form表单基础知识
    表格排版及其表格嵌套
    HTML表格,table,thead,tbody,tfoot,th,tr,td,的属性以及跨行,跨列
    垃圾收集,内存问题
    JS预解析机制
    python ==》 内置函数
    python ==》 递归
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4218070.html
Copyright © 2011-2022 走看看