結果
問題 |
No.1262 グラフを作ろう!
|
ユーザー |
|
提出日時 | 2020-10-17 22:57:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 316 ms / 3,000 ms |
コード長 | 592 bytes |
コンパイル時間 | 2,151 ms |
コンパイル使用メモリ | 196,348 KB |
最終ジャッジ日時 | 2025-01-15 11:24:40 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 96 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:27:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | int n; scanf("%*d%d",&n); | ~~~~~^~~~~~~~~~~~ main.cpp:29:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | rep(i,n) scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; vector<int> phi; void build_phi(int n){ phi.resize(n+1); iota(phi.begin(),phi.end(),0); for(int i=2;i<=n;i++) if(phi[i]==i) { for(int j=i;j<=n;j+=i) phi[j]=phi[j]/i*(i-1); } } int main(){ build_phi(1e6); vector<lint> res(1e6+1); for(int i=1;i<=1e6;i++){ for(int j=i;j<=1e6;j+=i){ res[j]+=i*phi[j/i]; } } int n; scanf("%*d%d",&n); vector<int> a(n); rep(i,n) scanf("%d",&a[i]); lint ans=0; rep(i,n) ans+=res[a[i]]-a[i]; printf("%lld\n",ans); return 0; }