結果
問題 | No.1514 Squared Matching |
ユーザー |
|
提出日時 | 2022-06-09 15:33:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 4,000 ms |
コード長 | 699 bytes |
コンパイル時間 | 1,377 ms |
コンパイル使用メモリ | 168,148 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-21 05:35:32 |
合計ジャッジ時間 | 2,190 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; int U=pow(N,1.0/3); int L=N/(U+1)/(U+1); vector<int>large(U+2),small(L+1); // small[i]=1以上 i 以下の整数のうち、平方因子を持たないものの個数 // large[i]=1以上N/i/i以下の整数のうち、平方因子を持たないものの個数 int ans=0; for(int i=1;i<=L;i++){ small[i]=i; for(int d=2;d*d<=i;d++)small[i]-=small[i/d/d]; int cnt=sqrt(N/i); ans+=cnt*cnt*(small[i]-small[i-1]); } large[U+1]=small[L]; for(int i=U;i>0;i--){ int R=N/i/i; large[i]=R; for(int d=2;d*d<=R;d++)large[i]-=i*d<=U?large[i*d]:small[R/d/d]; ans+=i*i*(large[i]-large[i+1]); } cout << ans; }