题目链接:
力扣https://leetcode-cn.com/problems/calculate-money-in-leetcode-bank/
【分析】先除,看看多少个整周的,再取余,把剩下几天的加进去。
class Solution {public int totalMoney(int n) {int ans = 0, i;int t = n / 7;int k = n % 7;int w = 28;for(i = 0; i < t; i++){ans += w;w += 7;}k = t + k;for(i = t + 1; i <= k; i++){ans += i;}return ans;}
}