• hdu 5150(水题)


    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(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
     
    Source
     
    题意:一个数如果与小于等于它的非负整数的最大公约数是1,那么他就是P-number,给出一个子序列,问里面的P-number之和.
    题解:注意不仅仅是素数,1也是P-number
    #include<stdio.h>
    #include<iostream>
    #include<string.h>
    #include <stdlib.h>
    #include<math.h>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
    const int N = 1005;
    int p[N];
    void init(){
        for(int i=2;i<=1000;i++){
            if(!p[i]){
                for(int j=i*i;j<=1000;j+=i){
                    p[j] = true;
                }
            }
        }
    
    }
    int main()
    {
        init();
        int n;
        while(scanf("%d",&n)!=EOF){
            int sum = 0;
            for(int i=1;i<=n;i++){
                int v;
                scanf("%d",&v);
                if(!p[v]) sum+=v;
            }
            printf("%d
    ",sum);
        }
        return 0;
    }
  • 相关阅读:
    struct和typedef struct彻底明白了
    jsoncpp使用
    JsonCpp使用注意
    vscode 远程 Linux 开发环境搭建
    Ubuntu 更换国内源
    java~PECS原则
    DLL劫持——DLL sideloading 这玩意从EDR检测厂商看,就S1有防护能力
    apache jmeter报告模板
    http压测工具 jmeter 安装配置
    golang项目部署
  • 原文地址:https://www.cnblogs.com/liyinggang/p/5672415.html
Copyright © 2020-2023  润新知