This article mainly introduces php's method of finding out the number of input files within a specified range and the square root is also the number of input files. The example shows php's method of determining the number of input files, which has some reference value, you can refer to the example in this article to find out the number of input files in the specified range in php 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."
";}} 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.