1 # include <iostream> 2 # include <time. h> 3 # include <math. h> 4 # include <assert. h> // use assert. the assert macro in H restricts the calling of invalid functions; 5 using namespace STD; 6 7 // determines whether it is a prime number 8 int is_prime (int x) // name the predicate (a function used to determine whether a transaction has a certain feature) in the form of is_xxx. the return value of int type is true if it is not 0, and false if it is 0; 9 {10 assert (x> = 0); // when x> = 0 fails, the program will terminate the exception and give a prompt; 11 if (x = 1) return 0; 12 int m = floor (SQRT (x) + 0.5); // rounding to avoid floating point errors, the cause of SQRT (X) is: if a number is 0 ~ SQRT (x) cannot be divisible, so it ranges from 0 ~ X cannot be divisible. 13 for (INT I = 2; I <= m; I ++) 14 {15 if (X % I = 0) // If X has other factors, it can be concluded that X is not a prime number; 16 return 0; 17} 18 return 1; 19} 20 21 int main () 22 {23 clock_t start, end; // time definition 24 int I, m; 25 CIN> m; 26 start = clock (); 27 for (I = m-2; I> = 3; I --) 28 {29 If (is_prime (I) & is_prime (I + 2) 30 {31 cout <I <''<I + 2 <Endl; 32 break; 33} 34} 35 end = clock (); 36 cout <"time used =" <(double) (end-Start)/clocks_per_sec <Endl; 37 return 0; 38 39}