I always use factor 3.
I just think: based on what I know now, how long would it probably take to write it - optimistic -?
Multiplying this by 3 is justified by the unknown unknows, bugfixing, communication, changing scope and assuming stuff is more simple than it actually is.
Works like a charm for me in most cases.
For problems where the solution is still unknown, I tend to break it up in small cycles, with a best-case estimate. At the end of every cycle we adjust and align, so that the customer can decide for himself whether to proceed, restart or abort.