Guest User

Untitled

a guest
Dec 6th, 2015
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. <?php
  2. $_fp = fopen("php://stdin", "r");
  3. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  4. if ($_fp) {
  5. $nums = Array(); $goods = Array();
  6. while (($line = fgets($_fp)) !== false) {
  7. $line = trim($line);
  8. $nums[] = $line;
  9. }
  10.  
  11. if (is_numeric($nums[0]) && is_numeric($nums[1]) || $nums[0]<=$nums[1]) {
  12. for ($i = $nums[0]; $i<$nums[1]; $i++) {
  13. $test = $i*$i;
  14. $k = strlen($test);
  15. for ($j=0; $j<$k; $j++) {
  16. $first = substr($test,0,$j);
  17. $second = str_replace($first, "", $test);
  18. if (strlen($second)>0 && $second>0 && ($first+$second)==$i) $goods[] = $i;
  19. }
  20.  
  21. }
  22. }
  23. $goods = array_unique($goods);
  24. if (count($goods)>0) {
  25. echo implode(" ", $goods);
  26. } else {
  27. echo "INVALID RANGE";
  28. }
  29.  
  30. fclose($_fp);
  31. } else {
  32. echo "INVALID RANGE";
  33. }
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment