【Leetcode】NO.1716 计算力扣银行的钱(Python)【打卡】([leetcode] no.1716 calculation force deduction of bank money (Python) [punch in])

题目 1716. 计算力扣银行的钱

Hercy 想要为购买第一辆车存钱。他 每天 都往力扣银行里存钱。

最开始,他在周一的时候存入 1 块钱。从周二到周日,他每天都比前一天多存入 1 块钱。在接下来每一个周一,他都会比 前一个周一 多存入 1 块钱。

给你 n ,请你返回在第 n 天结束的时候他在力扣银行总共存了多少块钱。

思路

每周每天加周数,从0开始算;余数为天数;

代码


class Solution:
    def totalMoney(self, n: int) -> int:
        total = 0
        for i in range(1,n+1):
            total += (i-1)//7 + (i-1)%7+1 # 周数整除+余数天数
        return total

————————

Title 1716 Calculate the power to deduct money from the bank

Hercy wants to save money for her first car. He deposits money in the Likou bank every day.

At first, he deposited a dollar on Monday. From Tuesday to Sunday, he deposited 1 yuan more every day than the previous day. In the following Monday, he will deposit 1 yuan more than the previous Monday.

Here you are n, please return to the total amount of money he deposited in Likou bank at the end of day n.

thinking

Add weeks per day per week, starting from 0; The remainder is days;

code


class Solution:
    def totalMoney(self, n: int) -> int:
        total = 0
        for i in range(1,n+1):
            total += (i-1)//7 + (i-1)%7+1 # 周数整除+余数天数
        return total