Skip to content

Commit 0ac00e4

Browse files
authored
Merge pull request #2 from sir-gon/devel
[Hacker Rank]: Project Euler #1: Multiples of 3 and 5 solved ✓. Cover…
2 parents 2f43e26 + d4f33e1 commit 0ac00e4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/lib/exercises/src/hackerrank/projecteuler/euler001.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ unsigned long HACKERRANK_PROJECTEULER_euler001(int a, int b, int n) {
3939
// Since, we need the sum of multiples less than N
4040
n = n - 1;
4141

42-
unsigned long lcm = (a * b) / HACKERRANK_PROJECTEULER_gcd(a, b);
42+
unsigned long gcd = HACKERRANK_PROJECTEULER_gcd(a, b);
43+
if (gcd == 0) {
44+
return 0;
45+
}
46+
47+
unsigned long lcm = (a * b) / gcd;
4348

4449
return HACKERRANK_PROJECTEULER_sum_of_arithmetic_progression(n, a) +
4550
HACKERRANK_PROJECTEULER_sum_of_arithmetic_progression(n, b) -

src/tests/unit/lib/hackerrank/projecteuler/euler001.testcases.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[
2+
{ "a": 0, "b": 0, "n": 0, "expected": 0 },
23
{ "a": 3, "b": 5, "n": 10, "expected": 23 },
34
{ "a": 5, "b": 3, "n": 10, "expected": 23 },
45
{ "a": 3, "b": 5, "n": 100, "expected": 2318 },

0 commit comments

Comments
 (0)