### Posts Tagged “SPOJ”

$\{(x_1,x_2,\cdots,x_n)|0\le x_1\le X_1, 0\le x_2\le X_2, \cdots, 0\le x_n\le X_n\}$

$a_1x_1+a_2x_2+\cdots+a_nx_n=b$

$\{\mathbf{x}|0\le x_i\le X_i,\mathbf{a}^T\mathbf{x}\le b\}$

$\{(x,y)|0\le x\le 4,0\le y\le 3,x+y\le 5\}$

SPOJ24. Small factorials[FCTRL2]就是阶乘计算加高精度运算。以下是用内置大数支持的perl, php, java, ruby, python, haskell, bash, scheme等语言实现的代码。

main = interact $unlines . map (\i -> show$ f !! read i) . tail . words
where f = scanl (*) 1 [1 ..]


### perl

#!/usr/bin/perl -w

use strict;
use Math::BigInt lib => 'GMP';

my @f = ();
push @f, Math::BigInt->new(1);
for (my $i = 1;$i <= 100; ++$i) { push @f,$f[$#f]->copy()->bmul($i);
}
chomp(my $re = <STDIN>); for (my$ri = 1; $ri <=$re; ++$ri) { chomp(my$n = <STDIN>);
print "$f[$n]\n";
}


### php

As I cannot find any appropriate haskell brushes for SyntaxHighlighter, I developed one by myself. You can download it here, I do hope it will be helpful. If you find any bugs or have any suggestions, please comment here or email me.

/* ... */
) );

3. 大功告成。

main = do
input <- getContents
putStr $unlines$ map show $doEMP$ map read \$ words input

doEMP [] = []
doEMP (a:b:o) = a + b : doEMP o