【UVA】1210 - Sum of Consecutive Prime Numbers
2014-08-15 18:29
357 查看
普通的求区间连续和的问题,一开始以为是区间移动,但是怕UVA数据太严,直接打表,后来发现自己的担心是多余的。
打表的话效率可能不是很高.
AC代码:
14044972 | 1210 | Sum of Consecutive Prime Numbers | Accepted | C++ | 0.049 | 2014-08-15 10:30:11 |
AC代码:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<map> #include<set> #include<list> #include<cmath> #include<string> #include<sstream> #include<ctime> using namespace std; #define _PI acos(-1.0) #define INF (1 << 10) #define esp 1e-9 #define MOD 100000007 typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> pill; /*=========================================== ===========================================*/ #define MAXD 10000 + 1 #define MAX_SIZE 6000000 int Prime_sum[MAXD]; int _count[MAX_SIZE] = {0}; int size = 1; void Get_Prime(){ int vis[MAXD] = {0}; Prime_sum[0] = 0; for(int i = 2 ; i < MAXD ; i++)if(!vis[i]){ if(size == 0) Prime_sum[size ++] = i; else{ Prime_sum[size] = Prime_sum[size - 1] + i; size++; } for(int j = i * i ; j < MAXD ; j += i) vis[j] = 1; } return ; } void init(){ Get_Prime(); for(int i = 1 ; i < size ; i++) for(int j = 0 ; j < i ; j++){ int t = Prime_sum[i] - Prime_sum[j]; _count[t] ++; } } int main(){ init(); int n; while(scanf("%d",&n) && n){ printf("%d\n",_count ); } return 0; }
相关文章推荐
- Sum of Consecutive Prime Numbers - UVa 1210 水题
- 习题10-6 UVA - 1210 Sum of Consecutive Prime Numbers 连续素数之和(滑动窗口)
- Sum of Consecutive Prime Numbers UVA - 1210 连续素数之和
- Sum of Consecutive Prime Numbers UVA - 1210
- UVa1210 - Sum of Consecutive Prime Numbers(欧拉筛法即线性筛法)
- UVA - 1210 - Sum of Consecutive Prime Numbers
- UVa 1210 - Sum of Consecutive Prime Numbers
- UVa 1210 - Sum of Consecutive Prime Numbers(滑动窗口)
- [UVa1210]Sum of Consecutive Prime Numbers(前缀和,打表)
- UVa 1210 (高效算法设计) Sum of Consecutive Prime Numbers
- UVa 1210 - Sum of Consecutive Prime Numbers
- Uva-1210 Sum of Consecutive Prime Numbers
- UVa1210 - Sum of Consecutive Prime Numbers
- UVa 1210 - Sum of Consecutive Prime Numbers
- UVA 1210(p343)----Sum of Consecutive Prime Numbers
- UVA 1210 Sum of Consecutive Prime Numbers
- UVA 1210 Sum of Consecutive Prime Numbers(素数打表)
- UVa1210 Sum of Consecutive Prime Numbers
- UVA 1210 Sum of Consecutive Prime Numbers(数论)
- UVa 1210 - Sum of Consecutive Prime Numbers