This is working, hilariously inefficient. Need to rewrite probably looking at prime factors