Skip to content

Instantly share code, notes, and snippets.

@shoya140
Created October 2, 2012 23:54
Show Gist options
  • Save shoya140/3824091 to your computer and use it in GitHub Desktop.
Save shoya140/3824091 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
my $count = 0;
my $max = 12000;
my $upper = 1/2;
my $lower = 1/3;
for (my $i = 1; $i <= $max; $i++) {
for (my $j = 1; $j < $i; $j++) {
my $flag = 1; #flag 1 is true 0 is false
for (my $k = 1; $k < $j; $k++) {
if($k != 1 && $i % $k == 0 && $j % $k == 0){
$flag = 0;
last;
}
}
if($flag == 1 && $j/$i > $lower && $j/$i < $upper){
$count ++;
}
}
}
print("The answer is $count \n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment