Php finds out the number of input files in the specified range and the square root is also the number of input files,
This example describes how php can find the number of input files in a specified range and the square root is also the number of input files. Share it with you for your reference. The details are as follows:
I. Requirements:
Two values X and Y are given to calculate the number of input values in this range, and the square root of them is required to be the number of input values. Where 1 <= x <= y <10 14
Ii. solution:
<? Phperror_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 you want to calculate in $ min, $ max: the number of input files and its square root is also the number of input files. // This is equivalent to obtaining a sqrt ($ min )~ Sqrt ($ max) Number of times // 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. "<br/>" ;}}} 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";?>
I hope this article will help you with php programming.