use bigint; $p=129402307; sub f{ my($n,$m)=@_; $n?$m?$m&1?f($n,$m-1)*$n%$p:f($n*$n%$p,$m/2):1:0; } print f<>%$p,<>%($p-1)