This sound like the MacKeeper trojan has infected your system. Beware of Googling how to remove it as the search results include the MacKeeper trojan so if your problem isn't due to it you will inadvertently install it.
It is such a malevolent infection I'm unclear as to why Apple doesn't have a clear and unambiguous solution posted somewhere prominent for all Apple users to access. My son recently suffered from at university in the last week of his essays. One tell-tale sign, apart from the flickering and the mouse pointer being uncontrollable, is tediously long boot-up time.
I'm going to check out a different forum with a question about it in case anyone has a definitive way to remove it. Booting in Safe Mode and then applying MalwareBytes scan worked for my son initially but it came back after a couple of hours. I think as well as the scan some files need to be removed manually but which ones and where are they? Without removing them it seems to redownload itself or in some way reinstall itself.