1-
2-https://ide.codingblocks.com/s/224282
BOTH THESE CODES ARE COORECT. BUT THERE IS A ERROR OF TIME LIMIT. PLEASE EXPLAIN ME A MORE EFFICIENT WAY OF THIS PROBLEM.
1-
2-https://ide.codingblocks.com/s/224282
BOTH THESE CODES ARE COORECT. BUT THERE IS A ERROR OF TIME LIMIT. PLEASE EXPLAIN ME A MORE EFFICIENT WAY OF THIS PROBLEM.
this is just O(1) solution that I suggest. First calculate the numbers of numbers below N divisible a, let their count be c1 then the sum of all these numbers should be a * ( 1 + 2 + 3 + c1 terms) . Do the same for b. Then subtract from the answer the same thing for their lcm.
the answer is coming wrong. or i did not understand properly.if i take N=20.
then sum of 3 multiples=63, sum of 5 multiples =30 .total 93. lcm=20. remain 93-20=73. but answer is 78
I think you didn’t understand completely
How do you get the sum of multiples of 5 as 30. It should be 50. and their lcm i.e. 15 has only a single multiple below 20 i.e. 15 so common 15 so ans is 30 + 50 - 15
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.