Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $_fp = fopen("php://stdin", "r");
- /* Enter your code here. Read input from STDIN. Print output to STDOUT */
- if ($_fp) {
- $nums = Array(); $goods = Array();
- while (($line = fgets($_fp)) !== false) {
- $line = trim($line);
- $nums[] = $line;
- }
- if (is_numeric($nums[0]) && is_numeric($nums[1]) || $nums[0]<=$nums[1]) {
- for ($i = $nums[0]; $i<$nums[1]; $i++) {
- $test = $i*$i;
- $k = strlen($test);
- for ($j=0; $j<$k; $j++) {
- $first = substr($test,0,$j);
- $second = str_replace($first, "", $test);
- if (strlen($second)>0 && $second>0 && ($first+$second)==$i) $goods[] = $i;
- }
- }
- }
- $goods = array_unique($goods);
- if (count($goods)>0) {
- echo implode(" ", $goods);
- } else {
- echo "INVALID RANGE";
- }
- fclose($_fp);
- } else {
- echo "INVALID RANGE";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment