TLE how to optimize this

ques : https://hack.codingblocks.com/app/practice/3/674/problem

code : https://ide.codingblocks.com/s/220840

showing tle, output is correct
how to optimize it?

please give me some time to think of the optimisation

sure no issues… thanks

i think this question has something to do with gcd of n & m
and then count no of multiple of n uptil z
count no of multiple of m uptil z
then subtract the common ones

I am not getting how gcd will help here… still i will try to do
thanks a lot!!

try out a example
like
n = 6
m = 12
z = 30
then
multiples of n will be
6 12 18 24 30
that of m
12 24
to ab hume kitne x h jo x%n or x%m == 0 de rahe h
that would be 6,12,18,24,30
->5
total hume kitne multiple mil rhae h 7
jisme se 2 redudant h
because gcd is not 1
had it been 1 then koi overlapping multiple nhi hota

1 Like

okay thora idea mil gya… i will implement the same

1 Like