How do I generate a number for a lottery and later proves its existence
You could use HMAC for this. HMAC is available in pretty much every crypto library out there.

The process would work like this. Randomly pick A and C. For simplicity, let's assume they are strings (of any length). Compute $B=HMAC(A,C)$. Publish $B$. Once someone guesses $A$, you publish $C$. Anyone can then verify that $B=HMAC(A,C)$.

As long as a good hash function is used, and $C$ is sufficiently long (say 128 bits), knowing $B$ should not help anyone compute $A$.



The benefits of doing this over what you propose in the question is that it is much simpler, faster, and the values generated are much smaller. For factorization to be hard enough, your primes will have to be around 1000 bits each.