1716.cpp (263B)
1 class Solution { 2 public: 3 int totalMoney(int n) { 4 const int whole = n / 7, rest = n % 7; 5 int res = whole * (7 * whole + 49) / 2; 6 7 for (int i = 1; i <= rest; i++) { 8 res += whole + i; 9 } 10 11 return res; 12 } 13 };