結果

問題 No.1514 Squared Matching
ユーザー momoyuu
提出日時 2023-04-28 13:17:36
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 783 ms / 4,000 ms
コード長 478 bytes
コンパイル時間 3,571 ms
コンパイル使用メモリ 245,924 KB
実行使用メモリ 393,872 KB
最終ジャッジ日時 2024-11-17 13:52:05
合計ジャッジ時間 16,218 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

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