Sum Sum Sum
来源:互联网 发布:mac os x 10.11.3 编辑:程序博客网 时间:2024/05/17 01:17
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 numberX P-number if there is not a positive number that is less thanX 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 integerN(1≤N≤1000) . The second line containsN integers. Each integer is between 1 and 1000.
Output
For each test case, output the sum of P-numbers of the sequence.
Sample Input
35 6 7110
Sample Output
120大牛请无视,水题,(==有时间再做难题吧),思路就是判断每一个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的和。
输入样例
35 6 7110
输出样例
120
0 0
- Sum
- sum
- sum
- Sum
- Sum
- Sum
- sum
- Sum
- sum
- Sum
- sum
- Sum
- sum
- Sum Sum Sum
- HDU5150 Sum Sum Sum
- HDU - 5150 Sum Sum Sum
- hdu 5150 sum sum sum
- hdu 5150 Sum Sum Sum
- 华东交通大学2013年ACM“双基”程序设计竞赛
- 多线程 -- 可等待的计时器内核对象
- java enum(枚举)使用详解 + 总结
- Java学习笔记——利用接口和observer实现对象监视
- List集合之间的连接
- Sum Sum Sum
- 通达OA 常用内置函数示例(图文)
- 多线程 -- 原子访问
- UIBinder template should be in client package.
- 黑马程序员 反射
- 一个可以直接使用的可用iptables配置的stateless NAT实现
- hdu - 1029 -Ignatius and the Princess IV
- 10.文件流
- 【设计模式】——六原则