結果

問題 No.1201 お菓子配り-4
ユーザー chielochielo
提出日時 2020-08-28 22:17:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,443 ms / 4,000 ms
コード長 684 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 76,956 KB
最終ジャッジ日時 2024-04-26 13:17:11
合計ジャッジ時間 18,520 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
76,368 KB
testcase_01 AC 763 ms
76,416 KB
testcase_02 AC 1,056 ms
76,508 KB
testcase_03 AC 550 ms
76,288 KB
testcase_04 AC 302 ms
76,476 KB
testcase_05 AC 632 ms
76,416 KB
testcase_06 AC 146 ms
76,032 KB
testcase_07 AC 338 ms
76,416 KB
testcase_08 AC 797 ms
76,692 KB
testcase_09 AC 601 ms
76,956 KB
testcase_10 AC 65 ms
74,752 KB
testcase_11 AC 194 ms
76,604 KB
testcase_12 AC 1,137 ms
76,416 KB
testcase_13 AC 90 ms
76,288 KB
testcase_14 AC 73 ms
76,168 KB
testcase_15 AC 901 ms
76,672 KB
testcase_16 AC 326 ms
76,288 KB
testcase_17 AC 412 ms
76,428 KB
testcase_18 AC 116 ms
76,800 KB
testcase_19 AC 113 ms
76,160 KB
testcase_20 AC 37 ms
52,608 KB
testcase_21 AC 41 ms
52,352 KB
testcase_22 AC 37 ms
52,224 KB
testcase_23 AC 37 ms
51,968 KB
testcase_24 AC 36 ms
52,608 KB
testcase_25 AC 36 ms
52,224 KB
testcase_26 AC 37 ms
52,096 KB
testcase_27 AC 36 ms
52,224 KB
testcase_28 AC 38 ms
52,608 KB
testcase_29 AC 37 ms
51,968 KB
testcase_30 AC 1,443 ms
76,928 KB
testcase_31 AC 1,430 ms
76,288 KB
testcase_32 AC 1,432 ms
76,636 KB
testcase_33 AC 1,427 ms
76,672 KB
testcase_34 AC 1,438 ms
76,544 KB
testcase_35 AC 881 ms
76,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd

def sum_of_floor(n, p, q):
    s = 0
    t = gcd(p, q)
    p, q = p // t, q // t
    z = 1
    while q > 0 and n > 0:
        t = p // q
        s = s + z * t * n * (n + 1) // 2
        p = p - q * t
        t = n // q
        s = s + z * p * t * (n + 1) - z * t * (p * q * t + p + q - 1) // 2
        n = n - q * t
        t = (n * p) // q
        s = s + z * t * n
        n = t
        p, q = q, p
        z = -z
    return s

n = int(input())
m = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(m):
        ans += sum_of_floor(b[j], a[i], b[j]) * 2
print(ans % (10 ** 9 + 7))
0