SGARDEN WA

First i am calculating the length of each cycle. Then that length is anumber in which two cases are possible: either the number is a prime number or a composite number (1 is handled too!). So if it is a prime number,then 1 is stored in the variable arr2[that prime number][1]. And if it is composite number, then it is broken down into its prime factors (using isprime function). And the value of power of that prime number is stored in arr2[that prime number][1]. each time ‘last’ variable is calculated to check the maximum value of that prime number whose power has been changed from 0( that is we have stored some number in it). Then during multiplication, loop runs ‘power’ times for a prime number. and while doing multiplication if ans >= 1000000007 mod operation is applied… Please help! @berezin

http://www.codechef.com/viewsolution/4336385

The problem is in your second part when the no is composite… See you are finding the biggest power of prime in the no and assign it to the array without comparing it with the value of the number originally stored at that position.

For eg. For this input

1

8

8 2 1 3 4 5 7 6

power of 2 will be 1 because of 6 ( 2^1 * 3^1 )… but it should me 3 because of 8…

Hope it works fine with this modification. :slight_smile:

P.S. Why are you using the 2D array arr2 when you are only using it arr2[j][1] values and not using arr2[j][0] anywhere. You should use 1D array and save memory and processing time. :slight_smile:

1 Like

Thankyou so much for going through my code… Yeah! That was a mistake… and I have corrected it! But I am still getting WA.

And I am using 2D array because powers will be stored corresponding to that prime number whose power is calculated…

Yes it will be stored at arr2[i][1] and not at arr2[i][0]. So what’s the use of it. :confused:
Try debugging your code by printing the data. It helps very much. :slight_smile: