I can give you a good tip for the highest common factor. Use this algorithm:

Numbers A,B

loop:

Switch if necessary so that A>=B

C=B mod A (C=B%A in c++)

if(C==0) Answer is B, break;

otherwise repeat with numbers B,C

end loop

This is a really fast algorithm. From what I know, it could be the fastest in existence.

I guess you can probably turn that into code yourself but if you need help just say.

Numbers A,B

loop:

Switch if necessary so that A>=B

C=B mod A (C=B%A in c++)

if(C==0) Answer is B, break;

otherwise repeat with numbers B,C

end loop

This is a really fast algorithm. From what I know, it could be the fastest in existence.

I guess you can probably turn that into code yourself but if you need help just say.