help needed in Little Shino and Path Divisor problem hackerearth

i am getting wa please help .
question link


my answer code link
https://pastebin.com/Dhgaibam
thanks in advance

Change line no. 55 to : if(w/j == j).

My modified solution : https://ideone.com/yFqT8a