Getting WA in Factor tree

Can anyone help me in getting bug in my code for factor tree. I have used MO’s algo and was getting WA for 3 rd subtask. and first two subtask were passed > I am not able to get the bug in my code because of which it fails for n=100000 .
Code Link :- CodeChef: Practical coding for everyone

I think you are facing overflow issue try changing Integer to Long and check if there is any overflow.

@rds_98 I have used long everywhere in calculating the result. I tried finding any overflow issue for 4 days but was not able to. Please see if you can

static ArrayList<Integer>[] val;
static ArrayList<Integer>[] tree;
static ArrayList<Integer> euler,eulerLevel;

Here I need to take long only because they store vertex no. which is 10^5 so there are no chances of overflow here. and in case If I am take them a s long and try to access elements it will show error as array indices cannot be long

Has anyone any idea that how can I run one correct code and this one large cases to find out the error

You can build a tree like 1 -> 2 -> 3 -> 4 -> 5 … and random array of 2 * 3 * 5 * 7 … values
for queries [1, n] like this q queries.