Founds

Numbers

My solution for the Numbers problem of Round 1A of Google Code Jam 2008 contest. It works too long for Large input.


#!/usr/bin/perl
use Math::BigFloat;
use POSIX;

$N = <STDIN>;

for ($iN = 0; $iN < $N; $iN++) {
    $n = <STDIN>;
    $sqfive = Math::BigFloat->new(5);
    $sqfive->bsqrt();
    $three = Math::BigFloat->new(3);
    $result = $three + $sqfive;
    $result->bpow($n);
    $str = "000" . $result->bstr();
    ($main,$rest) = split(/\./, $str);
    $otv = substr($main, -3);
    print "Case #". ($iN + 1) . ": $otv\n";
}