Split prime number and
Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 48614 accepted submission (s): 21227
Problem description splits an even number into two sums of different prime numbers. How can we split them?
The input contains some positive and even numbers. The input value does not exceed 10000, And the number does not exceed 500. In case of 0, it ends.
Output corresponds to each even number. The output is split into numbers of different prime numbers, and each result occupies one row.
Sample input30260
Sample output32
Question: give an even number and ask how many methods are there to split this even number into two different prime numbers for addition.
Question: Calculate the prime number before the even number and save it in the array. Then, try every possible number.
1 # include <bits/stdc ++. h> 2 using namespace STD; 3 int N; 4 int A [5500]; 5 Int num; 6 int isprime (int n) 7 {// return 1 to indicate that the result is a prime number, 0 is a non-prime number. No input exception is detected here. 8 double n_sqrt; 9 If (n = 2 | n = 3) return 1; 10 if (N % 6! = 1 & N % 6! = 5) return 0; 11 n_sqrt = floor (SQRT (double) n); 12 for (INT I = 5; I <= n_sqrt; I ++ = 6) 13 {14 if (N % (I) = 0 | n % (I + 2) = 0) return 0; 15} 16 return 1; 17} 18 void prime () 19 {20 num = 0; 21 for (INT I = 2; I <= N; I ++) 22 {23 if (isprime (I) 24 {25 A [num ++] = I; 26} 27} 28} 29 int main () 30 {31 32 While (~ Scanf ("% d", & N), n) 33 {34 memset (A, 0, sizeof (a); 35 prime (); int ans = 0; 36 For (INT I = 0; I <num; I ++) 37 {38 for (Int J = I + 1; j <num; j ++) 39 {40 if (a [I] + A [J] = N) 41 {42 // printf ("% d \ n", a [I], A [J]); 43 ans ++; 44} 45} 46} 47 printf ("% d \ n", ANS); 48} 49 return 0; 50}
Hdu2098 split prime number and (prime number + brute force)