标签:
Description
Every even number greater than 4 can be
written as the sum of two odd prime numbers.
8 = 3 + 5. Both 3 and 5 are odd prime numbers.
20 = 3 + 17 = 7 + 13.
42 = 5 + 37 = 11 + 31 = 13 + 29 = 19 + 23.
Input
Output
Sample Input
8 20 42 0
Sample Output
8 = 3 + 5 20 = 3 + 17 42 = 5 + 37
1 #include<iostream> 2 #include<cstdlib> 3 #include<cstdio> 4 #include<cstring> 5 #include<algorithm> 6 #include<cmath> 7 using namespace std; 8 bool isprime ( int k ) 9 { 10 int t = sqrt ( k + 0.5 ) ; 11 for ( int i = 2 ; i <= t ; i ++ ) 12 if ( k % i == 0 ) 13 return false ; 14 return true ; 15 } 16 int main() 17 { 18 // freopen ("a.txt" , "r" , stdin ); 19 int n ; 20 while ( scanf ("%d", &n) , n ) 21 { 22 int i ; 23 int t = n / 2 ; 24 for ( i = 3 ; i <= t ; i += 2 ) 25 if ( isprime ( i ) && isprime ( n - i ) ) 26 break ; 27 printf ( "%d = %d + %d\n" , n , i , n - i ) ; 28 } 29 return 0; 30 }
标签:
原文地址:http://www.cnblogs.com/get-an-AC-everyday/p/4272108.html