結果

問題 No.1201 お菓子配り-4
ユーザー chielochielo
提出日時 2020-08-28 22:17:15
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,608 ms / 4,000 ms
コード長 684 bytes
コンパイル時間 1,258 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 77,644 KB
最終ジャッジ日時 2023-08-08 20:58:20
合計ジャッジ時間 21,754 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
77,072 KB
testcase_01 AC 826 ms
77,416 KB
testcase_02 AC 1,143 ms
77,324 KB
testcase_03 AC 609 ms
77,436 KB
testcase_04 AC 340 ms
77,520 KB
testcase_05 AC 712 ms
77,424 KB
testcase_06 AC 179 ms
77,380 KB
testcase_07 AC 376 ms
77,644 KB
testcase_08 AC 867 ms
77,524 KB
testcase_09 AC 668 ms
77,292 KB
testcase_10 AC 100 ms
77,492 KB
testcase_11 AC 242 ms
77,312 KB
testcase_12 AC 1,273 ms
77,516 KB
testcase_13 AC 127 ms
77,044 KB
testcase_14 AC 106 ms
77,152 KB
testcase_15 AC 1,021 ms
77,280 KB
testcase_16 AC 378 ms
77,308 KB
testcase_17 AC 462 ms
77,484 KB
testcase_18 AC 149 ms
77,584 KB
testcase_19 AC 144 ms
77,104 KB
testcase_20 AC 71 ms
71,316 KB
testcase_21 AC 72 ms
71,532 KB
testcase_22 AC 71 ms
71,132 KB
testcase_23 AC 72 ms
71,388 KB
testcase_24 AC 69 ms
71,504 KB
testcase_25 AC 71 ms
71,284 KB
testcase_26 AC 72 ms
71,412 KB
testcase_27 AC 72 ms
71,516 KB
testcase_28 AC 72 ms
71,444 KB
testcase_29 AC 72 ms
71,516 KB
testcase_30 AC 1,602 ms
77,428 KB
testcase_31 AC 1,602 ms
77,400 KB
testcase_32 AC 1,604 ms
77,540 KB
testcase_33 AC 1,608 ms
77,604 KB
testcase_34 AC 1,598 ms
77,504 KB
testcase_35 AC 955 ms
77,452 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