- print "input :";
- chomp ($num=<STDIN>);
- foreach (100..(10**($num)-1)){
- my $t=$_;
- my $n=10**($num-1);
- foreach(0..($num-3)){
- if(($t/$n)>=1){$i=$num-$_; last;}
- $n/=10;
- }
- foreach(0..($i-1)) {
- @arr[$_]=($t%10);
- $t/=10;
- }
- my $lenth=@arr;
- my $sum;
- while(@arr){
- $sum+=((pop @arr)**($lenth));
- }
- print "The Daffodils Num. is $_"."\\n" if $_==$sum;
- }
- #该片段来自于http://www.codesnippet.cn/detail/210120131786.html
来源: http://www.codesnippet.cn/detail/210120131786.html