結果

問題 No.1019 最小格子三角形
ユーザー maspymaspy
提出日時 2020-03-09 07:22:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,278 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 29,844 KB
最終ジャッジ日時 2023-08-30 12:33:28
合計ジャッジ時間 4,977 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python3.8
import sys
read = sys.stdin.buffer.read1
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import lru_cache
import numpy as np
MOD = 10 ** 9 + 7

N = int(read())


def prime_table(N):
    is_prime = np.zeros(N, np.bool)
    is_prime[2] = 1
    is_prime[3::2] = 1
    for p in range(3, N, 2):
        if p * p >= N:
            break
        if is_prime[p]:
            is_prime[p * p:: p + p] = 0
    primes = np.where(is_prime)[0]
    return is_prime, primes


def mobius_table(N, primes):
    mu = np.ones(N, np.int64)
    mu[0] = 0
    for p in primes:
        mu[p::p] *= -1
        pp = p * p
        if p < N:
            mu[pp::pp] = 0
    return mu


@lru_cache(None)
def F(N):
    x_max = int(N ** .5)
    x = np.arange(1, x_max + 1, dtype=np.int64)
    y_max = np.sqrt(N - x * x).astype(int)
    S_xplus = (x * (1 + 2 * y_max) % MOD).sum() % MOD
    return S_xplus


def f(N):
    Nsq = int(N ** .5)
    is_prime, primes = prime_table(Nsq + 10)
    mu = mobius_table(Nsq + 10, primes)
    F_values = np.array([0] + [F(N // (n * n)) for n in range(1, Nsq + 1)], np.int64)
    x = (mu[: Nsq + 1] * F_values * np.arange(Nsq + 1, dtype=np.int64) % MOD).sum() % MOD
    return (24 * x - 16) % MOD


print(f(N))
0