in reply to Re^2: Divisors for a number
in thread Divisors for a number
#!/usr/bin/perl use warnings; use strict; my $n = <>; # read the input my $r = ''; my $p = 2; while ($n > 1) { if ($n % $p == 0) { $r .= "$p, "; # . is the concatenation operator $n /= $p; } else { ++$p; } } print "$r\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Divisors for a number
by rasy (Initiate) on Mar 03, 2015 at 23:59 UTC |