计算N位数字的自幂数(水仙花数)

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

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;
}