Reverse factorial

前端 未结 17 1464
南笙
南笙 2020-12-05 03:12

Well, we all know that if N is given it\'s easy to calculate N!. But what about the inverse?

N! is given and you are about to find N - Is that possible ? I\'m curio

17条回答
  •  一生所求
    2020-12-05 03:47

    C/C++ code for what the factorial (r is the resulting factorial):

    int wtf(int r) {
        int f = 1;
    
        while (r > 1)
            r /= ++f;
    
        return f;
    }
    

    Sample tests:

    Call: wtf(1)
    Output: 1
    
    Call: wtf(120)
    Output: 5
    
    Call: wtf(3628800)
    Output: 10
    

提交回复
热议问题