Error_reporting (E_ALL ); Ini_set ("display_errors", 1 ); // Avoid timeout Set_time_limit (0 ); $ T1 = microtime (); Function isPlalindrome ($ num ){ $ Str = "$ num "; $ Len = strlen ($ num ); $ K = intval ($ len/2) + 1; // Obtain the middle digit For ($ j = 0; $ j <$ k; $ j ++ ){ If ($ str {$ j }! = $ Str {$ len-1-$ j }){ Return false; } } Return true; } Function showPlalindrome ($ min, $ max ){ // Because the value is calculated in $ min, the return number between $ max and its square root is also the return number. // Therefore, it is equivalent to obtaining a sqrt ($ min )~ Sqrt ($ max) No. // Its square value ranges from $ min ~ $ Max is also the number of replies // $ Min ~ $ Max is a continuous positive integer, so it can reduce a lot of computations, otherwise ...... $ Start = sqrt ($ min ); $ End = sqrt ($ max ); For ($ I = $ start; $ I <$ end; $ I ++ ){ If (isPlalindrome ($ I) & isPlalindrome ($ n = $ I * $ I )){ Echo $ n ." "; } } } ShowPlalindrome (1,00000000000000 ); $ T2 = microtime (); $ Starttime = explode ("", $ t1 ); $ Endtime = explode ("", $ t2 ); $ Totaltime = $ endtime [0]-$ starttime [0] + $ endtime [1]-$ starttime [1]; $ Timecost = sprintf ("% s", $ totaltime ); Echo "page Running time: $ timecost seconds "; ?> |