The two numbers nearest 2000 which are exactly divisible by 4, 7, 8, 6, 5 are ____ and ____. Who answer first wil be marked as the brainllist
Answers
Step 1: Find the LCM of given numbers.
LCM of 4, 7, 8, 6 and 5 is 840.
Step 2: Divide 2000 by 840 and find the remainder.
The remainder would be 320.
Step 3: Add and subtract the remainder with the number.
2000 - 320 = 1680
2000 + 320 = 2320
∴ The two numbers nearest 2000 which are exactly divisible by 4, 7, 8, 6, 5 are 1680 and 2320.
It was easy enough to find with simple programming and the modulo operator. The closest workable number above 2000 is 2520. The closest workable number below 2000 is 1680.
#!/usr/bin/perl
$num = 2000;
while ($num != 1)
{ $num--;
if (($num % 4) || ($num % 7) || ($num % 8) || ($num % 6) || ($num % 5)) {
;
} else { print "$num\n"; }
}
$num = 2000;
while ($num != 4000)
{ $num++;
if (($num % 4) || ($num % 7) || ($num % 8) || ($num % 6) || ($num % 5)) {
;
} else { print "$num\n"; }
}
Output:
1680 <- closest number below 2000
840 <- next one
2520 <- closest number above 2000
3360 <- next one