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(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大牛请无视,水题,(==有时间再做难题吧),思路就是判断每一个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(1≤N≤1000)。 第二行为 N个整数,每个整数的范围都是1到1000。
输出描述
对于每组测试数据,输出P-number的和。
输入样例
3 5 6 7 1 10
输出样例
12 0