Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/opt/local/bin/perl | ||
use strict; | ||
use warnings; | ||
|
||
use Math::Big::Factors qw(factors_wheel); | ||
|
||
for my $num (1..99) { | ||
my @factors = factors_wheel($num); | ||
print "$num\n" if scalar(@factors) == 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/perl | ||
use strict; | ||
use warnings; | ||
|
||
# 最小の素因数を返すサブルーチン | ||
# 引数が素数だった場合はundefを返す | ||
sub get_factor { | ||
my $target = shift; | ||
for my $num (2 .. $target-1) { | ||
if ($target % $num == 0) { | ||
return $num; | ||
} | ||
} | ||
return; | ||
} | ||
|
||
TARGET: for my $num (1..99) { | ||
my $first_factor = get_factor($num); | ||
if (!defined($first_factor)) { | ||
next TARGET; | ||
} | ||
|
||
my $second_factor = get_factor($num / $first_factor); | ||
if (!defined($second_factor)) { | ||
print "$num\n"; | ||
} | ||
} |