#!/usr/bin/perl

#
# sample.pl - This program calculates the sum of all numbers divisible
# by n between 1 and m.
#

print "This program finds the sum of all numbers divisible by n between 1 and m.\n";
print "Enter n, the dividend    : "; $n = <STDIN>; chomp($n);
print "Enter m, the upper bound : "; $m = <STDIN>; chomp($m);

$c = 0;				# Temporary counter to add up squares

for($i = 1; $i <= $m; $i++) {	# All numbers between 1 and $m, inclusive
  if($i % $n == 0) {		# If $i mod $n equals 0 (divisible)
    $c = $c + $i;		# Add $i to current value of $c
  }
}

print "The sum of all numbers divisible by $n between 1 and $m is $c.\n";
