結果
| 問題 | 
                            No.1201 お菓子配り-4
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-02-15 21:17:37 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,015 bytes | 
| コンパイル時間 | 149 ms | 
| コンパイル使用メモリ | 82,432 KB | 
| 実行使用メモリ | 83,356 KB | 
| 最終ジャッジ日時 | 2024-07-18 04:35:10 | 
| 合計ジャッジ時間 | 48,298 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 35 TLE * 1 | 
ソースコード
# https://maspypy.github.io/library/mod/floor_sum_of_linear.hpp
# !sum((x * a + b) // mod for x in range(L, R))
from math import ceil
def floor_sum_of_linear(L: int, R: int, a: int, b: int, mod: int) -> int:
    """
    ```
    sum((x * a + b) // mod for x in range(L, R))
    ```
    """
    if L >= R:
        return 0
    res = 0
    b += L * a
    N = R - L
    if b < 0:
        k = ceil(-b / mod)
        b += k * mod
        res -= N * k
    while N:
        q, a = a // mod, a % mod
        res += N * (N - 1) // 2 * q
        if b >= mod:
            q, b = b // mod, b % mod
            res += N * q
        N, b = (a * N + b) // mod, (a * N + b) % mod
        a, mod = mod, a
    return res
if __name__ == "__main__":
    N = int(input())
    M = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    ans = 0
    for a in A:
        for b in B:
            ans += floor_sum_of_linear(1, b + 1, a, 0, b)
    ans *= 2
    ans %= 10**9 + 7
    print(ans)