Split Prime andTime
limit:1000MS
Memory Limit:32768KB
64bit IO Format:%i64d &%i64 U
Description
To split an even number into two different prime numbers, how many methods are there?
Input
The input contains some positive even numbers, the value will not exceed 10000, the number will not exceed 500, if in the event of 0, the end.
Output
corresponding to each even, the output is split into the number of different primes, each result occupies a row.
Sample Input
30 26 0
Sample Output
3 2 The key is to do a pre-treatment
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include < queue> #include <vector> #include <iomanip> #include <math.h>using namespace std; #define FIN Freopen ("Input.txt", "R", stdin), #define INF 0x3f3f3f3f#define lson l,m,rt<<1#define rson m+1,r, Rt<<1|1typedef Long Long Ll;int p[10005];int s[5005];int main () { //fin int cas=0; for (int i=2, i<=10000; i++) { if (p[i]==0) {for (int j=i+i; j<=10000; j=j+i) { p[j]= 1 ; }}} for (int i=2; i<=10000; i++) { if (p[i]==0) s[cas++]=i; } int n; while (~SCANF ("%d", &n) &&n) { int cnt=0; for (int i=3; i<n/2; i+=2) { if (!p[i]&&!p[n-i]) cnt++; } printf ("%d\n", CNT); }}
HDU 2098 split primes and number theory