factorial cpp implementation