結果

問題 No.1262 グラフを作ろう!
ユーザー LayCurseLayCurse
提出日時 2020-10-16 22:42:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 583 ms / 3,000 ms
コード長 4,956 bytes
コンパイル時間 3,853 ms
コンパイル使用メモリ 213,392 KB
実行使用メモリ 24,692 KB
最終ジャッジ日時 2023-09-28 04:27:12
合計ジャッジ時間 65,770 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 568 ms
16,372 KB
testcase_01 AC 560 ms
16,424 KB
testcase_02 AC 571 ms
16,428 KB
testcase_03 AC 570 ms
16,644 KB
testcase_04 AC 540 ms
15,720 KB
testcase_05 AC 552 ms
16,640 KB
testcase_06 AC 534 ms
15,660 KB
testcase_07 AC 545 ms
15,948 KB
testcase_08 AC 568 ms
16,648 KB
testcase_09 AC 558 ms
16,424 KB
testcase_10 AC 559 ms
20,260 KB
testcase_11 AC 565 ms
16,356 KB
testcase_12 AC 573 ms
16,488 KB
testcase_13 AC 565 ms
16,416 KB
testcase_14 AC 543 ms
16,372 KB
testcase_15 AC 555 ms
16,432 KB
testcase_16 AC 564 ms
16,572 KB
testcase_17 AC 566 ms
16,680 KB
testcase_18 AC 581 ms
16,432 KB
testcase_19 AC 554 ms
16,012 KB
testcase_20 AC 560 ms
16,372 KB
testcase_21 AC 583 ms
16,652 KB
testcase_22 AC 559 ms
15,612 KB
testcase_23 AC 568 ms
16,376 KB
testcase_24 AC 567 ms
16,648 KB
testcase_25 AC 549 ms
15,812 KB
testcase_26 AC 558 ms
16,372 KB
testcase_27 AC 564 ms
16,424 KB
testcase_28 AC 562 ms
16,712 KB
testcase_29 AC 555 ms
16,644 KB
testcase_30 AC 548 ms
16,568 KB
testcase_31 AC 568 ms
16,484 KB
testcase_32 AC 559 ms
16,372 KB
testcase_33 AC 550 ms
16,432 KB
testcase_34 AC 567 ms
16,652 KB
testcase_35 AC 570 ms
16,420 KB
testcase_36 AC 565 ms
16,576 KB
testcase_37 AC 572 ms
16,644 KB
testcase_38 AC 565 ms
16,512 KB
testcase_39 AC 574 ms
16,480 KB
testcase_40 AC 565 ms
16,376 KB
testcase_41 AC 581 ms
16,644 KB
testcase_42 AC 569 ms
24,428 KB
testcase_43 AC 554 ms
24,416 KB
testcase_44 AC 559 ms
24,504 KB
testcase_45 AC 581 ms
24,388 KB
testcase_46 AC 558 ms
24,496 KB
testcase_47 AC 553 ms
24,392 KB
testcase_48 AC 564 ms
24,400 KB
testcase_49 AC 568 ms
24,432 KB
testcase_50 AC 560 ms
24,384 KB
testcase_51 AC 548 ms
24,444 KB
testcase_52 AC 548 ms
24,496 KB
testcase_53 AC 550 ms
24,472 KB
testcase_54 AC 561 ms
24,672 KB
testcase_55 AC 565 ms
24,504 KB
testcase_56 AC 561 ms
24,440 KB
testcase_57 AC 569 ms
24,428 KB
testcase_58 AC 559 ms
24,384 KB
testcase_59 AC 552 ms
24,672 KB
testcase_60 AC 577 ms
24,408 KB
testcase_61 AC 554 ms
24,448 KB
testcase_62 AC 568 ms
24,428 KB
testcase_63 AC 569 ms
24,456 KB
testcase_64 AC 553 ms
24,432 KB
testcase_65 AC 558 ms
24,268 KB
testcase_66 AC 555 ms
24,480 KB
testcase_67 AC 550 ms
24,596 KB
testcase_68 AC 553 ms
24,376 KB
testcase_69 AC 554 ms
24,556 KB
testcase_70 AC 568 ms
24,544 KB
testcase_71 AC 564 ms
24,456 KB
testcase_72 AC 564 ms
24,488 KB
testcase_73 AC 578 ms
24,428 KB
testcase_74 AC 573 ms
24,664 KB
testcase_75 AC 573 ms
24,440 KB
testcase_76 AC 573 ms
24,480 KB
testcase_77 AC 566 ms
24,432 KB
testcase_78 AC 561 ms
24,500 KB
testcase_79 AC 568 ms
24,440 KB
testcase_80 AC 568 ms
24,396 KB
testcase_81 AC 564 ms
24,384 KB
testcase_82 AC 567 ms
24,676 KB
testcase_83 AC 565 ms
24,428 KB
testcase_84 AC 564 ms
24,600 KB
testcase_85 AC 581 ms
24,508 KB
testcase_86 AC 576 ms
24,388 KB
testcase_87 AC 574 ms
24,396 KB
testcase_88 AC 574 ms
24,396 KB
testcase_89 AC 566 ms
24,692 KB
testcase_90 AC 580 ms
24,592 KB
testcase_91 AC 581 ms
24,444 KB
testcase_92 AC 570 ms
24,404 KB
testcase_93 AC 583 ms
24,396 KB
testcase_94 AC 576 ms
24,444 KB
testcase_95 AC 580 ms
24,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
// }
0