Oh god. The mind that produced that should be ... interesting to look at. From a safe distance of course
There's a minor 'bug' in the code: the +$n%$v*$v; does nothing and can be removed.
It looks for n = a*b*c where a,b,c are different primes.
Look at the problem from another angle: if you have an n = a*b*c and you try to divide n by all numbers between 2 and n-1, how many 'whole' divisions (with no modulo) would you get?
The answer is six:
a, b, c, ab, ac and bc
The only problem you'll have is with numbers which are n=a*a*a*b which also have six:
a, b, aa, ab, aaa, aab
(I don't have proof that there aren't more combinations that also produce exactly six divisors, but for the several I tried it looked correct)
So if we can check if n % a^3 == 0 and throw these away, we're fine.
This is what the code does in a very, very twisted way.
On second thought, the author maybe didn't think of the method himself, because of the mistake with $n%$v*$v, which is always 0. Maybe he meant n%v^2 which is also redundant, since we already checked for n%v^3.