Sum Sum Sum

Sum Sum Sum


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


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
大牛请无视,水题,(==有时间再做难题吧),思路就是判断每一个X数是不是P-Number,如果是的话就求和.(简单吧),题目中定义,如果不存在一个小于X的数Y,Y和X组成一个大于1的最大公约数,那么这个数X就是P-Number,只要理解这点,这个题目就简单了!


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    int n,sum;
    int array1[1001];
    int array2[1001];
    while(scanf("%d",&n)!=EOF)
    {
        memset(array1,0,sizeof(array1));
        memset(array2,0,sizeof(array2));
        sum=0;
        for(int i=0;i<n;i++)
        {
            cin>>array1[i];
        }
        for(int i=0;i<n;i++)
        {
            for(int j=1;j<array1[i];j++)
            {
                int a=array1[i];
                int b=j,c;
                c=a%b;
                while(c!=0)
                {
                    a=b;
                    b=c;
                    c=a%b;
                }
                if(b>1)
                {
                    array2[i]=1;
                }
            }
        }
        for(int i=0;i<n;i++)
        {
            if(array2[i]==0)
            {
                sum+=array1[i];
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}


突然发现可以看中文呢,英文不好的同学请看下面!



Sum Sum Sum


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


问题描述
对于x,如果不存在一个小于x的正数y使得x和y的最大公约数大于1,则我们把x称为P-number,反之则不是P-number。
现在给你一个整数的序列,你的任务是计算序列中P-number的和。
输入描述
输入有多组测试数据。
对于每组测试数据:
第一行为一个整数 N(1N1000)。 第二行为 N个整数,每个整数的范围都是1到1000。
输出描述
对于每组测试数据,输出P-number的和。
输入样例
3
5 6 7
1
10
输出样例
12
0

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值