QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#109473#1932. Sum of Consecutive Prime NumbersDontLike100 ✓13ms3416kbC++111.3kb2023-05-29 09:32:182023-05-29 09:32:21

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-29 09:32:21]
  • 评测
  • 测评结果:100
  • 用时:13ms
  • 内存:3416kb
  • [2023-05-29 09:32:18]
  • 提交

answer

#include <iostream>
int sumNums(int *nums,int left,int right);
using namespace std;
int main(int argc, char** argv) {
	int val = 0,count = 0, index = 0;
	int primnums[10001], primenum2[10001];
	int primnum = 2,nums = 0;
	int rightindex = 0,leftindex = 0;
	int xmax = 0, xmin = 0;
	int sum = 0;
	primnums[0] = 1;
	primnums[1] = 1;
	for (int i = 2; i <= 10000; i++) {
		if (primnums[i] == 0) {
			for (int j = 2 * i; j <= 10000; j += i) {
				primnums[j] = 1;
			}
		}
	}
	for (int i = 0; i <= 10000; i++) {
		if (primnums[i] == 0) {
			primenum2[index] = i;
			index++;
		}
	}
	while (cin >> val && val != 0) {
		rightindex = 0;
		while (primenum2[rightindex] < val) {
			rightindex++;
		}
		xmax = rightindex;
		leftindex = xmin;
		while (leftindex >= xmin && rightindex <= xmax && leftindex <= rightindex){
			sum = sumNums(primenum2,leftindex,rightindex);
			if (sum == val) {
				count++;
				leftindex++;
				rightindex++;
				continue;
			}
			if (sum > val) {
				rightindex--;
			}
			else {
				leftindex++;
				rightindex++;
			}
		}
		rightindex = 0;
		cout << count << endl;
		count = 0;
	}	
	return 0;
}
int sumNums(int* nums, int left, int right) {
	int res = 0;
	if(left == right)
		return nums[left];
	for (int m = left; m <= right; m++) {
		res += nums[m];
	}
	return res;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 13ms
memory: 3416kb

input:

3
17
41
666
1151
3264
2
5100
5999
311
6504
7451
7901
8819
863
9999
10000
7053
2914
827
302
12
3631
785
230
8011
1567
3198
2350
5307
3339
8929
9216
6479
4703
699
90
440
3926
1032
3329
3682
5764
1615
7961
53
9273
1275
4038
4923
540
7443
7837
1368
7746
1469
8505
4328
9480
6424
6678
1139
9763
1959
6707
...

output:

1
2
3
0
4
4
1
4
4
5
4
4
4
4
5
1
0
0
2
2
0
1
2
0
0
2
1
4
1
0
0
1
0
1
1
0
2
1
0
2
2
0
1
0
1
2
0
0
1
0
2
0
0
0
0
0
1
1
0
1
1
2
0
1
1
0
0
0
1
0
1
0
0
4
1
0
2
4
0
0
0
1
0
0
0
1
1
0
3
0
0
4
4
0
1
1
0
0
0
4

result:

ok 100 lines