Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为啥我数组范围开到12000反而不行?10001就能AC

Posted by Seasonal at 2016-05-02 14:05:08 on Problem 2739
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define maxn 10005
int prim[maxn] = { 0 };
int num[maxn];
int count = 0;

void init()
{
	for (int i = 2; i*i <= maxn; i++)
	{
		if (!prim[i])
		{
			for (int j = i*i; j <= maxn; j += i)
				prim[j] = 1;
		}
	}
	for (int i = 2; i <= maxn; i++)
		if (!prim[i])
			num[count++] = i;
}

int main()
{
	init();
	int n;
	while (scanf("%d", &n), n)
	{
		int ans = 0;
		for (int i = 0; i < count; i++)
		{
			int sum = 0;
			for (int j = i;; j++)
			{
				sum += num[j];
				if (sum == n)
				{
					ans++;
					break;
				}
				if (sum > n)
					break;
			}
			if (num[i] >= n)
				break;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator