Safe Square Root
PHP
Medium
4 views
Problem Description
Given x, print floor(sqrt(x)). If x is negative, print ERROR.
Input Format
One integer x.
Output Format
One integer or ERROR.
Official Solution
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$x=intval($inputText);
if($x<0){ echo 'ERROR'; exit; }
echo strval(intval(floor(sqrt($x))));
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!