Created
December 19, 2015 05:25
-
-
Save tomcha/17525d0413e3bf35093e to your computer and use it in GitHub Desktop.
ouyou7
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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
my $num; | |
my @prime; | |
print "2より大きい数字を1つ入力して下さい。>>"; | |
$num = <STDIN>; | |
chomp $num; | |
push @prime, 2; | |
# まず、お題の2からnまでの数字について、順番に考察するループ | |
for my $i(2..$num){ | |
# 1つずつ取り出した数字が素数かどうか検討し、素数であれば出力する。 | |
for my $p (@prime){ | |
if ($i % $p == 0){ | |
last; | |
} | |
if ($p == $prime[-1]){ | |
push @prime, $i; | |
} | |
} | |
} | |
print join ', ', @prime; | |
print "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment