力扣双周赛 -- 117(容斥原理专场)

力扣双周赛 -- 117(容斥原理专场)_第1张图片

 

class Solution {
public:
    long long c2(long long n)
    {
        return n > 1? n * (n - 1) / 2 : 0;
    }
    long long distributeCandies(int n, int limit) {
        
        
        return c2(n + 2) - 3 * c2(n - limit + 1) + 3 * c2(n - 2 * limit) - c2(n - 3 * limit - 1);
    }
};

你可能感兴趣的:(leetcode,算法,职场和发展)