I can't find what is wrong with this code

My idea is I store the prime factors of x in a set and then I iterate through each (i) in the set and each time I calculate the number of numbers which are divisible by (i power k) and that is gonna be the number of times this number is going to contribute to the answer. the code passes the first 2 samples but the last one it doesn't so could anyone tell me what could be the problem in my code?

You need to substract the contribution of the higher powers first.

this is my code 124067958

u mean if we find 2 in the set we have to subtract (n / 2 power k+1) from (n / 2 power k) and that is the number (2 power k) that contributes to the answer?

No, the contribution of some power isn't simply (n / x^power), you can see in my code I store this contribution in some map and simply subtract it.

i am sorry but can u explain the last for loop in ur code cuz i still dont get it