[HDU] [2098] Split Prime Sum

Problem Description

Loading...

Problem Analysis

This one still uses direct checking
though it already hints at the table-precomputation approach
but the table is still built with direct checking
so it is completely meaningless…

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<stdio.h>
#include<math.h>
int su(int a);
int main() {
	int i,j,k,n,g;
	int a[10000];
	for(i=2,j=0; i<=10010; i++) {
		if(su(i)==1) {
			a[j++]=i;
		}
	}
	while(scanf("%d",&n),n!=0) {
		for(i=0,g=0; i<n; i++) {
			for(k=j-1; k>i; k--) {
				if(a[k]==n-a[i])
					g++;
			}
		}
		printf("%d\n",g);
	}
	return 0;
}
int su(int a) {
	int i;
	for(i=2; i<=sqrt(a); i++) {
		if(a%i==0) break;
	}
	if(i>sqrt(a))
		return 1;
	else
		return 0;
}
This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...