There are dozens & dozens of code modules available (for the stealing, or free) and in different computer languages to answer your number theory problems.
All you have to do is assemble the fragments into a working program.
It is far more instructive to construct your own. If you build the code, you will have a better comprehension of the algorithm.
What computer programming language do you prefer?