i am in a similar situation
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 :
What is the reason behind this ?
I found my bug. I wasnât clearing my adjacency list. I canât believe I forgot it again. UghghghghgâŚ
How to calculate the two primes??
I tried it, but with mine calculated p1,p2, I am getting WA
It is quite easy. Though there could be couple of more ways, but here what I did :
- Took all the primes till 100 in a sorted manner.
- Product of all prime numbers at every even index stored in a separate variable, and odd indices in a separate variable.
- Now there was overflow for ONLY one of them.
- So i divided the larger one by 5 and multiplied the other with 5.
- Hereâs my beautiful java implementation.
- Make sure to read the comments from my code to see what were those numbers
can you explain this please. Thnaks
So you checked for p1 that it never gets out of bounds. But what for p2??
It does go out of bounds.
Your p1 and p2 are 614889782588491410 and 3749562977351496827
One of them is above the range 2000000000000000000
we can take the same value twice
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
what if there are 5 nodes in total and length selected is 4 then how to solve this