fork download
  1. #!/usr/bin/perl
  2. use bigint;
  3.  
  4. while(defined(my $line=<STDIN>)){
  5. chomp $line;
  6. $N = $line;
  7. printP($N);
  8. }
  9.  
  10. sub printP {
  11. ($N) = @_;
  12. my @A = ();
  13. $A[0][0] = 2; $A[0][1] = 1;
  14. $A[1][0] = 1; $A[1][1] = 1;
  15. my @R = ();
  16. $R[0][0] = 1; $R[0][1] = 0;
  17. $R[1][0] = 0; $R[1][1] = 1;
  18. my $P = 0;
  19.  
  20. foreach(1..$N){
  21. if($_ & 1){
  22. @R = multMat(\@A, \@R);
  23. $P += $R[0][0];
  24. }
  25. }
  26. print "$P\n";
  27. }
  28.  
  29. sub multMat {
  30. my ($A, $B) = @_;
  31. my @C = ();
  32. foreach my $i (0..1) {
  33. foreach my $j (0..1) {
  34. $C[$i][$j] = 0;
  35. }
  36. }
  37. foreach my $i (0..1) {
  38. foreach my $j (0..1) {
  39. foreach my $k (0..1) {
  40. $C[$i][$j] += ($A->[$i][$k] * $B->[$k][$j]);
  41. }
  42. }
  43. }
  44. return @C;
  45. }
  46.  
Success #stdin #stdout 0.05s 8552KB
stdin
Standard input is empty
stdout
Standard output is empty