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 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. For more information, see

 

 

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:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

<? Php

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. "<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.

 

Related Article

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.