Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Test 41/2
#perl 5.22.1 %isPrime=(2=>3,3=>5,5=>7,7=>11,11=>-1); $largestPrime=11; for (1..100){ primeFactors($_) } sub primeFactors{ my $wn=$number=shift; my @factorsList=(); my $test=2; $limit=sqrt($wn+1); while ($test < $limit){ if ($wn % $test){ $test= (exists $isPrime{$test})?$isPrime{$test}:$test+1; } else{ push @factorsList,$test; If($test>$largestPrime){ @isPrime{$test,$largestPrime}=(-1,$test); $largestPrime=$test; } $wn=$wn/$test; $limit=sqrt($wn+1) } } push @factorsList,$wn; if (scalar @factorsList == 1){ print "$number is prime\n"; $isPrime{$number}=1; } else{ print "$number :factors are ", join ",",@factorsList,($isPrime{scalar @factorsList})? "and is attractive\n":"\n" }; }
run
|
edit
|
history
|
help
0
Price_supriya
perl circle plot
Challenge 41 Task 1
XPPErrorLog
Prac 2 #2
hashes
Array_with_unshift_function
Array_with_shift_function
key_hash_function
Array_with_push_function