ExeW's blog

By ExeW, history, 3 years ago, In English

Hi,

I ran into a problem with answers in problemset 486A. My code says — if the number is even then print a half of it otherwise do something else.

Test case is 1 000 000 000 000 000 and "judging bot" or whatever doesn't take it as an even number. When I try the same number in terminal in my computer it works fine (answer 500 000 000 000 000).

Could you help?

My submission 113388721

  • Vote: I like it
  • -1
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +19 Vote: I do not like it

Codeforces is a 32-bit environment. Dumping the PHP_INT_MAX constant:

<?php
  var_dump(PHP_INT_MAX);
?>

in CF yields int(2147483647). I'm guessing that your computer is 64-bit and the code dumps something bigger.

When you read the huge integer and try to do math, it gets cast into a float instead of int because it is bigger than the maximum allowed integer.

<?php 
    $n = trim(fgets(STDIN)) + 0;
    var_dump($n);
?>

This will give float(1.0E+15) if I write 1000000000000000 as the input but int(100) if i write 100 as the input. Welcome to PHP.