Getting wrong answer

I am doing this question from codeforces…
https://codeforces.com/problemset/problem/1209/B
This is my code.


My approach is I kept changing the string until it becomes equal to itself again…
In that, I am calculating the maximum number of blub open.

hello @ashishnnnnn

ur line of thinking is correct.
let say x is the period of given sequences (ai,bi).
here ur code is not working because it may happen that u get same string back in time less than < x .
that means u will not explore all the states and which will surely give wrong result.

so iterate to some big numbers > x and manipulate ur string and count on bulbs and update ur maximum

There are ‘n’ number of (ai,bi) … so there will be n period(x)… So how will we decide… what number of iteration we should do…??

its a math problem bro, probably lcm will work here.

@ashishnnnnn
even in ediotrial they are taking lcm.

image
value of b can be 1 or 2 or 3 or 4 or 5.
their period will be 2,4,6,8,10
overall period will be lcm(2,4,6,8,10)=120
also a in worst case can be 5 .
so we need to iterate till 5 + period of sequence => 5 + 120=125

Thanks…
Understood :slight_smile: