結果

問題 No.1514 Squared Matching
ユーザー ForestedForested
提出日時 2021-05-22 11:26:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 377 ms / 4,000 ms
コード長 680 bytes
コンパイル時間 995 ms
コンパイル使用メモリ 88,392 KB
実行使用メモリ 9,512 KB
最終ジャッジ日時 2024-04-18 17:34:12
合計ジャッジ時間 8,163 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 374 ms
9,512 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 8 ms
5,376 KB
testcase_07 AC 74 ms
5,376 KB
testcase_08 AC 360 ms
9,216 KB
testcase_09 AC 312 ms
8,320 KB
testcase_10 AC 346 ms
8,960 KB
testcase_11 AC 359 ms
9,048 KB
testcase_12 AC 370 ms
9,144 KB
testcase_13 AC 372 ms
9,244 KB
testcase_14 AC 377 ms
9,344 KB
testcase_15 AC 371 ms
9,472 KB
testcase_16 AC 375 ms
9,344 KB
testcase_17 AC 376 ms
9,344 KB
testcase_18 AC 371 ms
9,472 KB
testcase_19 AC 376 ms
9,276 KB
testcase_20 AC 369 ms
9,472 KB
testcase_21 AC 374 ms
9,472 KB
testcase_22 AC 76 ms
5,376 KB
testcase_23 AC 151 ms
5,632 KB
testcase_24 AC 224 ms
6,976 KB
testcase_25 AC 301 ms
8,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>

std::size_t solve(std::size_t n) {
    std::vector<bool> is_square_free(n + 1, true);
    for (std::size_t i = 2; i * i <= n; ++i) {
        if (!is_square_free[i * i])
            continue;
        for (std::size_t j = i * i; j <= n; j += i * i)
            is_square_free[j] = false;
    }
    
    std::size_t ans = 0;
    for (std::size_t k = 1; k <= n; ++k) {
        if (is_square_free[k]) {
            std::size_t tmp = std::floor(std::sqrt((double) n / k));
            ans += tmp * tmp;
        }
    }
    return ans;
}

int main() {
    std::size_t n;
    std::cin >> n;
    std::cout << solve(n) << std::endl;
}
0