1 ~ 10 사이의 어떤 수로도 나누어 떨어지는 가장 작은 수는 2520입니다.
그러면 1 ~ 20 사이의 어떤 수로도 나누어 떨어지는 가장 작은 수는 얼마입니까?
알고리즘 : 그런거 없습니다. 그냥 나올때까지 돌립니다. --;
Python
This file contains hidden or 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
numList=range(1,21) | |
num=1 | |
while True: | |
isSearch=True | |
for n in numList: | |
r=num%n | |
if r!=0: | |
isSearch=False | |
num+=1 | |
break | |
if isSearch: | |
print(num) | |
break |
Ruby
This file contains hidden or 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
numList=Array.new(20) {|x| x+1} | |
num=1 | |
while true | |
isSearch=true | |
for i in numList | |
r=num%i | |
if r!=0 | |
isSearch=false | |
num+=1 | |
break | |
end | |
end | |
if isSearch | |
print(num) | |
break | |
end | |
end |
Perl
This file contains hidden or 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/perl | |
use strict; | |
use warnings; | |
my @number_list = (1..20); | |
my $num = 1; | |
while (1) { | |
my $is_search = 1; | |
foreach my $n (@number_list) { | |
my $r = $num % $n; | |
if ($r != 0) { | |
$is_search = 0; | |
$num+=1; | |
last | |
} | |
} | |
if ($is_search) { | |
print $num."\n"; | |
last; | |
} | |
} |