Php finds out the number of input files in the specified range and the square root is also the number of input files,

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.