We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
If you approached the question using AP and have removed the repeating elements (i.e., sum of multiples of 15) from the: sum of AP of 3 + sum of AP of 5, then the only thing you need to make sure is that integer overflow does not occur. This is the reason why your testcases 2 & 3 might not pass.
One trivial way to ensure that integer overflow doesn't occur is to use long long int for every variable.
Another way is to type cast befor overflow occurs for storing the intermediate values.
Here's my solution for your reference.
Project Euler #1: Multiples of 3 and 5
You are viewing a single comment's thread. Return to all comments →
If you approached the question using AP and have removed the repeating elements (i.e., sum of multiples of 15) from the: sum of AP of 3 + sum of AP of 5, then the only thing you need to make sure is that integer overflow does not occur. This is the reason why your testcases 2 & 3 might not pass. One trivial way to ensure that integer overflow doesn't occur is to use long long int for every variable. Another way is to type cast befor overflow occurs for storing the intermediate values. Here's my solution for your reference.