use strict; my $N = ; my @count = Fire($N); for(my $i = @count - 1; $i >= 0; $i--){ print @count[$i]; } print "\n"; sub Fire { my @box; my $set = 0; my $N = $_[0]; if($N % 3 == 0 && $N % 5 == 0) { $set = 4; }elsif($N % 3 == 0){ $set = 2; }elsif($N % 5 == 0){ $set = 2; }else{ $set = 0; } if($N == 1){ @box = $set; return @box; }else{ @box = Fire($N - 1); @box[0] += $set; if(@box[0] >= 10 ** 4){ @box[1] += @box / 10 **4; @box[0] %= 10**4; } my $length = @box; if($length > 1){ for(my $i = 1; $i <= $length - 1; $i++){ if(@box[0] >= 10 ** 4){ @box[$i+1] += @box[$i] / 10 **4; @box[$i] %= 10**4; } } } return @box; } }