結果

問題 No.1514 Squared Matching
ユーザー momoyuumomoyuu
提出日時 2023-04-28 13:17:36
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 823 ms / 4,000 ms
コード長 478 bytes
コンパイル時間 3,418 ms
コンパイル使用メモリ 245,700 KB
実行使用メモリ 393,984 KB
最終ジャッジ日時 2024-04-28 18:56:42
合計ジャッジ時間 17,210 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 764 ms
393,784 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 7 ms
9,216 KB
testcase_07 AC 130 ms
77,808 KB
testcase_08 AC 726 ms
379,648 KB
testcase_09 AC 625 ms
332,408 KB
testcase_10 AC 687 ms
359,880 KB
testcase_11 AC 720 ms
374,784 KB
testcase_12 AC 720 ms
385,024 KB
testcase_13 AC 725 ms
390,144 KB
testcase_14 AC 733 ms
392,148 KB
testcase_15 AC 748 ms
393,216 KB
testcase_16 AC 742 ms
393,708 KB
testcase_17 AC 751 ms
393,728 KB
testcase_18 AC 823 ms
393,856 KB
testcase_19 AC 786 ms
393,984 KB
testcase_20 AC 751 ms
393,884 KB
testcase_21 AC 760 ms
393,840 KB
testcase_22 AC 138 ms
81,512 KB
testcase_23 AC 332 ms
159,488 KB
testcase_24 AC 549 ms
237,696 KB
testcase_25 AC 659 ms
315,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ll n;
    cin>>n;
    vector<ll> cnt(n+2,0);
    for(ll i = 1;i*i<=n;i++){
        ll le = n / (i*i);
        cnt[1]++;
        cnt[le+1]--;
    }
    for(int i = 1;i<=n+1;i++) cnt[i] += cnt[i-1];
    for(ll i = 2;i*i<=n;i++){
        ll now = i * i;
        for(;now<=n+1;now+=i*i) cnt[now] = 0;
    }
    ll ans = 0;
    for(int i = 1;i<=n;i++) ans += cnt[i] * cnt[i];
    cout<<ans<<endl;
}
0