PATHETIC - Editorial

i am in a similar situation

1 Like

Why do we need to Greedily assign Prime Numbers to p1 and p2 ?
I am getting WA on when I assign p1 and p2 naively like this :
222

What is the reason behind this ?

Here u can check

Or

u can do in reverse order too , it will work

I found my bug. I wasn’t clearing my adjacency list. I can’t believe I forgot it again. :disappointed_relieved: Ughghghghg…

How to calculate the two primes??
I tried it, but with mine calculated p1,p2, I am getting WA

CODE LINK TO CALCULATE TWO PRIMES

1 Like

It is quite easy. Though there could be couple of more ways, but here what I did :

  1. Took all the primes till 100 in a sorted manner.
  2. Product of all prime numbers at every even index stored in a separate variable, and odd indices in a separate variable.
  3. Now there was overflow for ONLY one of them.
  4. So i divided the larger one by 5 and multiplied the other with 5.
  5. Here’s my beautiful java implementation.
  6. Make sure to read the comments from my code to see what were those numbers
1 Like

can you explain this please. Thnaks

So you checked for p1 that it never gets out of bounds. But what for p2?? :face_with_raised_eyebrow:
It does go out of bounds.
Your p1 and p2 are 614889782588491410 and 3749562977351496827
One of them is above the range 2000000000000000000

1 Like

we can take the same value twice

See my earlier comment

Yeah, I got it
Thanks a lot !!

+1

I printed 1170615464648030300 (LCM(1, 2, 3, …, 100) which is less than 2e18) for each node and got WA.
Is it mentioned in the problem that the product of values of nodes in each path can’t exceed 2e18? I can only see that the value of each node can’t exceed 2e18. Can someone please explain?

This is incorrect. Just try dividing this value by 64. The value has overflown long long

1 Like

what if there are 5 nodes in total and length selected is 4 then how to solve this