H. Đếm số chia hết cho 3 từ 1 đến n


Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 256M

Problem type

Đề bài: Viết hàm dem_chia_het_3(n) để đếm có bao nhiêu số chia hết cho 3 từ 1 đến n.

Input: Một số nguyên dương n (1 ≤ n ≤ 1000)

Output: Số lượng số chia hết cho 3

Input:
10
Output:
3

Giải thích: Các số chia hết cho 3 là: 3, 6, 9

Input:
15
Output:
5

Giải thích: Các số: 3, 6, 9, 12, 15

def dem_chia_het_3(n):
    dem = 0
    for i in range(1, ___ + 1):
        if ___ % 3 == 0:
            dem += 1
    return ___

n = int(input())
print(dem_chia_het_3(n))

Comments

There are no comments at the moment.