Created
September 7, 2015 12:00
-
-
Save itsazzad/28886371d5b1a61d5067 to your computer and use it in GitHub Desktop.
Special multiplication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Enter your code here. Read input from STDIN. Print output to STDOUT */ | |
$handle = fopen ("php://stdin","r"); | |
$t = fgets($handle); | |
$LIMIT=100000; | |
function specialX($number){ | |
global $LIMIT; | |
for($i=$number;$i<$LIMIT;$i++){ | |
if(($fours=strpos($i,'0'))===false){ | |
$forfours=$i; | |
}else{ | |
$forfours=substr($i, 0, $fours); | |
} | |
$fours=strlen($forfours); | |
if(count(array_diff(str_split($forfours), array_fill(0, $fours,'4')))==0){ | |
$zeros=strlen($i)-$fours; | |
return 2*$fours+$zeros; | |
} | |
} | |
} | |
for($i=0; $i<$t; $i++) | |
{ | |
$number = trim(fgets($handle)); | |
print(specialX($number)."\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment