結果
問題 | No.1262 グラフを作ろう! |
ユーザー | LayCurse |
提出日時 | 2020-10-16 22:42:36 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 751 ms / 3,000 ms |
コード長 | 4,956 bytes |
コンパイル時間 | 2,866 ms |
コンパイル使用メモリ | 216,764 KB |
実行使用メモリ | 16,640 KB |
最終ジャッジ日時 | 2024-07-20 23:02:00 |
合計ジャッジ時間 | 68,834 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 574 ms
16,384 KB |
testcase_01 | AC | 746 ms
16,512 KB |
testcase_02 | AC | 703 ms
16,512 KB |
testcase_03 | AC | 635 ms
16,512 KB |
testcase_04 | AC | 562 ms
15,872 KB |
testcase_05 | AC | 567 ms
16,512 KB |
testcase_06 | AC | 566 ms
15,616 KB |
testcase_07 | AC | 555 ms
16,128 KB |
testcase_08 | AC | 613 ms
16,512 KB |
testcase_09 | AC | 728 ms
16,512 KB |
testcase_10 | AC | 629 ms
16,384 KB |
testcase_11 | AC | 673 ms
16,512 KB |
testcase_12 | AC | 642 ms
16,512 KB |
testcase_13 | AC | 608 ms
16,512 KB |
testcase_14 | AC | 570 ms
16,512 KB |
testcase_15 | AC | 600 ms
16,512 KB |
testcase_16 | AC | 628 ms
16,512 KB |
testcase_17 | AC | 583 ms
16,512 KB |
testcase_18 | AC | 648 ms
16,384 KB |
testcase_19 | AC | 579 ms
16,128 KB |
testcase_20 | AC | 617 ms
16,512 KB |
testcase_21 | AC | 706 ms
16,384 KB |
testcase_22 | AC | 544 ms
15,616 KB |
testcase_23 | AC | 581 ms
16,384 KB |
testcase_24 | AC | 631 ms
16,640 KB |
testcase_25 | AC | 546 ms
16,000 KB |
testcase_26 | AC | 582 ms
16,512 KB |
testcase_27 | AC | 601 ms
16,512 KB |
testcase_28 | AC | 594 ms
16,512 KB |
testcase_29 | AC | 596 ms
16,512 KB |
testcase_30 | AC | 614 ms
16,512 KB |
testcase_31 | AC | 687 ms
16,384 KB |
testcase_32 | AC | 622 ms
16,512 KB |
testcase_33 | AC | 580 ms
16,384 KB |
testcase_34 | AC | 628 ms
16,512 KB |
testcase_35 | AC | 650 ms
16,384 KB |
testcase_36 | AC | 562 ms
16,384 KB |
testcase_37 | AC | 667 ms
16,640 KB |
testcase_38 | AC | 610 ms
16,512 KB |
testcase_39 | AC | 665 ms
16,384 KB |
testcase_40 | AC | 593 ms
16,512 KB |
testcase_41 | AC | 592 ms
16,384 KB |
testcase_42 | AC | 616 ms
16,512 KB |
testcase_43 | AC | 597 ms
16,384 KB |
testcase_44 | AC | 624 ms
16,512 KB |
testcase_45 | AC | 614 ms
16,512 KB |
testcase_46 | AC | 584 ms
16,384 KB |
testcase_47 | AC | 591 ms
16,512 KB |
testcase_48 | AC | 606 ms
16,512 KB |
testcase_49 | AC | 594 ms
16,512 KB |
testcase_50 | AC | 594 ms
16,512 KB |
testcase_51 | AC | 751 ms
16,512 KB |
testcase_52 | AC | 570 ms
16,384 KB |
testcase_53 | AC | 564 ms
16,384 KB |
testcase_54 | AC | 569 ms
16,512 KB |
testcase_55 | AC | 596 ms
16,384 KB |
testcase_56 | AC | 556 ms
16,512 KB |
testcase_57 | AC | 570 ms
16,512 KB |
testcase_58 | AC | 605 ms
16,384 KB |
testcase_59 | AC | 561 ms
16,640 KB |
testcase_60 | AC | 582 ms
16,384 KB |
testcase_61 | AC | 572 ms
16,512 KB |
testcase_62 | AC | 604 ms
16,384 KB |
testcase_63 | AC | 600 ms
16,512 KB |
testcase_64 | AC | 554 ms
16,384 KB |
testcase_65 | AC | 547 ms
16,384 KB |
testcase_66 | AC | 577 ms
16,384 KB |
testcase_67 | AC | 596 ms
16,384 KB |
testcase_68 | AC | 541 ms
16,384 KB |
testcase_69 | AC | 561 ms
16,384 KB |
testcase_70 | AC | 613 ms
16,384 KB |
testcase_71 | AC | 552 ms
16,512 KB |
testcase_72 | AC | 562 ms
16,512 KB |
testcase_73 | AC | 593 ms
16,384 KB |
testcase_74 | AC | 563 ms
16,384 KB |
testcase_75 | AC | 562 ms
16,512 KB |
testcase_76 | AC | 566 ms
16,512 KB |
testcase_77 | AC | 557 ms
16,384 KB |
testcase_78 | AC | 611 ms
16,512 KB |
testcase_79 | AC | 576 ms
16,512 KB |
testcase_80 | AC | 567 ms
16,512 KB |
testcase_81 | AC | 593 ms
16,640 KB |
testcase_82 | AC | 577 ms
16,512 KB |
testcase_83 | AC | 561 ms
16,512 KB |
testcase_84 | AC | 595 ms
16,512 KB |
testcase_85 | AC | 558 ms
16,512 KB |
testcase_86 | AC | 565 ms
16,512 KB |
testcase_87 | AC | 585 ms
16,512 KB |
testcase_88 | AC | 595 ms
16,384 KB |
testcase_89 | AC | 575 ms
16,512 KB |
testcase_90 | AC | 581 ms
16,512 KB |
testcase_91 | AC | 606 ms
16,640 KB |
testcase_92 | AC | 599 ms
16,512 KB |
testcase_93 | AC | 589 ms
16,384 KB |
testcase_94 | AC | 594 ms
16,512 KB |
testcase_95 | AC | 578 ms
16,512 KB |
ソースコード
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; void*wmem; char memarr[96000000]; template<class S, class T> inline S min_L(S a,T b){ return a<=b?a:b; } template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline int rd_int(void){ int x; rd(x); return x; } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(long long x){ int s=0; int m=0; char f[20]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } int Prime_L(int N, int res[], void *mem=wmem){ int i; int a; int b; int sz = 1; const int r = 23000; bool*isprime; int*sf; int ss = 1; walloc1d(&isprime, r, &mem); walloc1d(&sf, r, &mem); isprime = (bool*)mem; sf = (int*)(isprime + r); N /= 2; res[0] = 2; b =min_L(r, N); for(i=(1);i<(b);i++){ isprime[i] = 1; } for(i=(1);i<(b);i++){ if(isprime[i]){ res[sz++] = 2*i+1; sf[ss] = 2*i*(i+1); if(sf[ss] < N){ while(sf[ss] < r){ isprime[sf[ss]] = 0; sf[ss] += res[ss]; } ss++; } } } for(a=r; a<N; a+=r){ b =min_L(a + r, N); isprime -= r; for(i=(a);i<(b);i++){ isprime[i] = 1; } for(i=(1);i<(ss);i++){ while(sf[i] < b){ isprime[sf[i]] = 0; sf[i] += res[i]; } } for(i=(a);i<(b);i++){ if(isprime[i]){ res[sz++] = 2*i+1; } } } return sz; } template<class T> int Factor_L(T N, T fac[], int fs[]){ T i; int sz = 0; if(N%2==0){ fac[sz] = 2; fs[sz] = 1; N /= 2; while(N%2==0){ N /= 2; fs[sz]++; } sz++; } for(i=3;i*i<=N;i+=2){ if(N%i==0){ fac[sz] = i; fs[sz] = 1; N /= i; while(N%i==0){ N /= i; fs[sz]++; } sz++; } } if(N > 1){ fac[sz] = N; fs[sz] = 1; sz++; } return sz; } template<class T> int Divisor_L(T N, T res[], void *mem = wmem){ int i; int j; int k; int s; int sz = 0; T*fc; int*fs; int fsz; walloc1d(&fc, 100, &mem); walloc1d(&fs, 100, &mem); fsz =Factor_L(N, fc, fs); res[sz++] = 1; for(i=(0);i<(fsz);i++){ s = sz; k = s * fs[i]; for(j=(0);j<(k);j++){ res[sz++] = res[j] * fc[i]; } } sort(res, res+sz); return sz; } int N; int A; int ps; int p[1000000]; int phi[1000000+1]; int ds; int d[1000000]; long long ans[1000000+1]; int main(){ int Q5VJL1cS, i, tU__gIr_; wmem = memarr; long long res = 0; ps =Prime_L(1000000, p); for(i=(0);i<(1000000+1);i++){ phi[i] = i; } for(Q5VJL1cS=(0);Q5VJL1cS<(ps);Q5VJL1cS++){ int j; auto &i = p[Q5VJL1cS]; for(j=(i);j<(1000000+1);j+=(i)){ phi[j] = phi[j] / i * (i-1); } } for(i=(1);i<(1000000+1);i++){ int t_ynMSdg; ds =Divisor_L(i, d); for(t_ynMSdg=(0);t_ynMSdg<(ds);t_ynMSdg++){ auto &j = d[t_ynMSdg]; ans[i] += j * phi[i/j]; } } rd(N); int a2conNHc = rd_int(); for(tU__gIr_=(0);tU__gIr_<(a2conNHc);tU__gIr_++){ rd(A); res += ans[A] - A; } wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20201003-1 // --- original code --- // int N, A; // int ps, p[1d6]; // int phi[1d6+1]; // int ds, d[1d6]; // ll ans[1d6+1]; // { // ll res = 0; // // ps = Prime(1d6, p); // rep(i,1d6+1) phi[i] = i; // rep[p](i,ps) rep(j,i,1d6+1,i) phi[j] = phi[j] / i * (i-1); // // rep(i,1,1d6+1){ // ds = Divisor(i, d); // rep[d](j,ds) ans[i] += j * phi[i/j]; // } // // rd(N); // REP(rd_int()){ // rd(A); // res += ans[A] - A; // } // wt(res); // }