TLE in SEGPROD (NOVEMBOR LONG CHALLENGE)

Can someone please spot out the time consuming factors in my code for the question https://www.codechef.com/NOV17/problems/SEGPROD/ from Novembor Long Challenge and how to get AC in all 3 subtasks(where to optimize! :(). I tried a lot to optimize but this is the bare minimum thing that has to be calculated in order to reach to the final answer.

Here’s the link to my submission : https://www.codechef.com/viewsolution/16258320

I am getting TLE in one test file each of subtask 1 and 2… and TLE in the first 2 test files of subtask 3.

Thanks, in advance. :slight_smile:

1 Like

I have just posted editorial for this problem here. Exactly explaining how to optimize as constraints were too tight.

1 Like

I have read your post, bro. :slight_smile:

But can you just take a quick glance at my code and probably say what can be some possible TLE causing factors and how can I rectify to get an AC. :slight_smile:

That would of greattt help !

I’m not much in c++, so i can’t say much. But i guess vectors are making your solution slow. Prefer using arrays when constraints are one of the tightest i have ever seen

Use arrays in place of vectors. Maximum number of prime factors of P will be 10. Enjoy coding!