結果

問題 No.1514 Squared Matching
コンテスト
ユーザー LyricalMaestro
提出日時 2026-07-10 01:18:01
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 2,388 ms / 4,000 ms
コード長 727 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 244 ms
コンパイル使用メモリ 96,488 KB
実行使用メモリ 474,620 KB
最終ジャッジ日時 2026-07-10 01:18:43
合計ジャッジ時間 39,047 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

## https://yukicoder.me/problems/no/1514

import math

def main():
    N = int(input())

    sqrt_array = []
    x = 1
    while x ** 2 <= N:
        sqrt_array.append(x ** 2)
        x += 1
    
    answer = 0
    finished = [False] * (N + 1)
    index = len(sqrt_array) - 1
    for j in range(1, N + 1): 
        if finished[j]:
            continue

        while index >= 0 and j * sqrt_array[index] > N:
            index -= 1

        if index >= 0:        
            answer += (index + 1) ** 2
            x = j
            for i in range(index + 1):
                finished[x * sqrt_array[i]] = True
    
    print(answer)





                





    
        















if __name__ == "__main__":
    main()
0