結果

問題 No.1514 Squared Matching
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-09-03 10:20:58
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 212 ms / 4,000 ms
コード長 709 bytes
コンパイル時間 5,217 ms
コンパイル使用メモリ 307,012 KB
実行使用メモリ 9,596 KB
最終ジャッジ日時 2023-09-03 10:21:09
合計ジャッジ時間 10,367 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 210 ms
9,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 5 ms
4,384 KB
testcase_07 AC 41 ms
4,540 KB
testcase_08 AC 203 ms
9,088 KB
testcase_09 AC 177 ms
8,552 KB
testcase_10 AC 192 ms
8,780 KB
testcase_11 AC 199 ms
9,016 KB
testcase_12 AC 205 ms
9,296 KB
testcase_13 AC 210 ms
9,596 KB
testcase_14 AC 209 ms
9,492 KB
testcase_15 AC 210 ms
9,428 KB
testcase_16 AC 210 ms
9,484 KB
testcase_17 AC 210 ms
9,452 KB
testcase_18 AC 212 ms
9,316 KB
testcase_19 AC 209 ms
9,440 KB
testcase_20 AC 212 ms
9,376 KB
testcase_21 AC 209 ms
9,308 KB
testcase_22 AC 43 ms
4,468 KB
testcase_23 AC 85 ms
5,652 KB
testcase_24 AC 126 ms
6,932 KB
testcase_25 AC 171 ms
8,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<int,int>;
#define sr string 
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
  int n;cin>>n;
  vc<bool>v(n+1,true); 
  vc<int>sqs;
  for(int i=2;i*i<=n;i++){
    sqs.pb(i*i);
    for(int j=i*i;j<=n;j+=i*i)v[j]=false;
  }
  int r=sqs.size();
  ll ans=0;
  for(int i=1;i<=n;i++)if(v[i]){
    while(r&&sqs[r-1]*i>n)r--;
    ans+=(ll)(r+1)*(r+1);
  }
  cout<<ans;
}
0