qwertyuiopoiuytrewqwertyuiop0987654321qwertyuiopoiuytrewq

Công khai 2 thành viên
• 6:29 p.m. 30 Tháng 10, 2025

s

xin chào bạn

  • main-py-2
    hello
...Xem thêm
• 6:27 p.m. 30 Tháng 10, 2025

x

from collections import Counter

def count_divisible_by_2019(S):
mod = 2019
count = Counter()
count[0] = 1 # ban đầu có 1 cách (đoạn rỗng)

current = 0
power10 = 1
ans = 0

# duyệt từ phải sang trái
for ch in reversed(S):
    digit = int(ch)
    current = (current + digit * power10) % mod
    ans += count[current]
    count[current] += 1
    power10 = (power10 * 10) % mod

return ans

--- MAIN ---

q = int(input())
for _ in range(q):
S = input().strip()
print(count_divisible_by_2019(S))

...Xem thêm