leetcode1006.笨阶乘

 


 

不难

class Solution {
public:
    int clumsy(int N) {
        int i;
        if(N==3) return 6;
        if(N==2||N==1) return N;
        int a=N*(N-1)/(N-2)+N-3;
        N-=4;
        int sign=1;
        long long res=a;
        if(N==0) return a;
        while(N>=4){
            a=N*(N-1)/(N-2)-N+3;
            res-=a;
            N-=4;
            cout<<-a<<endl;
            }
        //if(N<=0) return res;
        if(N==3){
            return res-6;
        }
        res-=N;
        return res;
    }
};

  

 

posted @ 2021-04-01 15:56  vdk  阅读(45)  评论(0)    收藏  举报