def reverse_factorial(num):
i = 1
while num > 1:
i += 1
num /= i
if num == 1:
return i
for num in [3628800, 479001600, 6, 18]:
print reverse_factorial(num)
ZGVmIHJldmVyc2VfZmFjdG9yaWFsKG51bSk6CiAgICBpID0gMQogICAgd2hpbGUgbnVtID4gMToKICAgICAgICBpICs9IDEKICAgICAgICBudW0gLz0gaQogICAgaWYgbnVtID09IDE6CiAgICAgICAgcmV0dXJuIGkKZm9yIG51bSBpbiBbMzYyODgwMCwgNDc5MDAxNjAwLCA2LCAxOF06CiAgICBwcmludCByZXZlcnNlX2ZhY3RvcmlhbChudW0p