結果

問題 No.1262 グラフを作ろう!
ユーザー saksak
提出日時 2020-11-28 19:19:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 577 ms / 3,000 ms
コード長 2,763 bytes
コンパイル時間 2,797 ms
コンパイル使用メモリ 209,012 KB
実行使用メモリ 34,452 KB
最終ジャッジ日時 2023-10-10 00:56:00
合計ジャッジ時間 39,229 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 474 ms
33,420 KB
testcase_01 AC 317 ms
31,224 KB
testcase_02 AC 493 ms
33,084 KB
testcase_03 AC 438 ms
33,676 KB
testcase_04 AC 73 ms
26,880 KB
testcase_05 AC 262 ms
29,716 KB
testcase_06 AC 58 ms
26,516 KB
testcase_07 AC 86 ms
27,144 KB
testcase_08 AC 331 ms
30,568 KB
testcase_09 AC 304 ms
31,756 KB
testcase_10 AC 245 ms
29,712 KB
testcase_11 AC 327 ms
30,832 KB
testcase_12 AC 437 ms
33,068 KB
testcase_13 AC 453 ms
33,804 KB
testcase_14 AC 207 ms
29,148 KB
testcase_15 AC 245 ms
30,872 KB
testcase_16 AC 343 ms
31,116 KB
testcase_17 AC 330 ms
30,816 KB
testcase_18 AC 513 ms
33,304 KB
testcase_19 AC 86 ms
27,136 KB
testcase_20 AC 178 ms
28,472 KB
testcase_21 AC 520 ms
34,068 KB
testcase_22 AC 50 ms
26,620 KB
testcase_23 AC 289 ms
30,960 KB
testcase_24 AC 322 ms
31,064 KB
testcase_25 AC 75 ms
27,188 KB
testcase_26 AC 109 ms
27,768 KB
testcase_27 AC 221 ms
28,956 KB
testcase_28 AC 196 ms
28,800 KB
testcase_29 AC 136 ms
28,012 KB
testcase_30 AC 171 ms
28,736 KB
testcase_31 AC 535 ms
34,092 KB
testcase_32 AC 289 ms
30,608 KB
testcase_33 AC 161 ms
28,756 KB
testcase_34 AC 261 ms
29,764 KB
testcase_35 AC 432 ms
33,112 KB
testcase_36 AC 167 ms
29,368 KB
testcase_37 AC 536 ms
34,044 KB
testcase_38 AC 267 ms
29,936 KB
testcase_39 AC 277 ms
30,792 KB
testcase_40 AC 248 ms
30,224 KB
testcase_41 AC 154 ms
28,196 KB
testcase_42 AC 415 ms
32,440 KB
testcase_43 AC 219 ms
29,328 KB
testcase_44 AC 257 ms
30,008 KB
testcase_45 AC 387 ms
31,508 KB
testcase_46 AC 116 ms
27,644 KB
testcase_47 AC 331 ms
32,412 KB
testcase_48 AC 360 ms
31,464 KB
testcase_49 AC 496 ms
33,656 KB
testcase_50 AC 403 ms
32,032 KB
testcase_51 AC 377 ms
32,220 KB
testcase_52 AC 146 ms
27,896 KB
testcase_53 AC 111 ms
27,664 KB
testcase_54 AC 496 ms
33,860 KB
testcase_55 AC 359 ms
31,600 KB
testcase_56 AC 156 ms
28,140 KB
testcase_57 AC 577 ms
34,044 KB
testcase_58 AC 475 ms
33,140 KB
testcase_59 AC 148 ms
28,076 KB
testcase_60 AC 542 ms
33,500 KB
testcase_61 AC 221 ms
29,552 KB
testcase_62 AC 458 ms
33,292 KB
testcase_63 AC 458 ms
34,232 KB
testcase_64 AC 300 ms
31,028 KB
testcase_65 AC 96 ms
27,328 KB
testcase_66 AC 212 ms
29,468 KB
testcase_67 AC 151 ms
28,188 KB
testcase_68 AC 97 ms
27,348 KB
testcase_69 AC 165 ms
28,412 KB
testcase_70 AC 335 ms
31,356 KB
testcase_71 AC 316 ms
31,288 KB
testcase_72 AC 442 ms
32,232 KB
testcase_73 AC 504 ms
34,272 KB
testcase_74 AC 393 ms
33,540 KB
testcase_75 AC 367 ms
32,040 KB
testcase_76 AC 308 ms
30,896 KB
testcase_77 AC 390 ms
32,756 KB
testcase_78 AC 352 ms
31,684 KB
testcase_79 AC 491 ms
33,264 KB
testcase_80 AC 349 ms
31,092 KB
testcase_81 AC 418 ms
32,860 KB
testcase_82 AC 512 ms
34,312 KB
testcase_83 AC 329 ms
30,836 KB
testcase_84 AC 299 ms
31,084 KB
testcase_85 AC 548 ms
34,124 KB
testcase_86 AC 427 ms
32,656 KB
testcase_87 AC 469 ms
33,500 KB
testcase_88 AC 398 ms
32,808 KB
testcase_89 AC 275 ms
30,472 KB
testcase_90 AC 340 ms
34,288 KB
testcase_91 AC 340 ms
34,356 KB
testcase_92 AC 353 ms
34,276 KB
testcase_93 AC 393 ms
34,308 KB
testcase_94 AC 487 ms
34,304 KB
testcase_95 AC 464 ms
34,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

struct Sieve {
  struct num { 
    ll f, x, n;
    bool operator== (const num &a) const { return f==a.f&&x==a.x&&n==a.n; };
    num  operator+  (const num &a) const { return (num){f+a.f,x+a.x,n+a.n}; };
  };
  vector<num> pfac; num p0;
  Sieve(ll x=pow(10,6)+10) {
    p0 = {-1,0,0};
    pfac.resize(x,p0);
    repr(i,2,x) {
      if (pfac[i]==p0) {
        for (ll j=1; i*j<=x; j++) {
          if (pfac[i*j]==p0) {
            if (j%i==0) pfac[i*j] = pfac[j] + (num){0,1,0};
            else pfac[i*j] = {i,1,j};
          }
        }
      }
    }
  }
  bool isp(ll n) { return pfac[n].f==n; }
  vector<p_ll> factors(ll n) {
    vector<p_ll> result;
    while (n>=2) { 
      result.push_back(make_pair(pfac[n].f,pfac[n].x));
      n=pfac[n].n;
    }
    return result;
  }
};

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

int main() {
  ll N, M; cin >> N >> M;
  ll A[M]; rep(i,M) cin >> A[i];

  // rep(i,M) {
  //   ll result = 0;
  //   repr(j,1,A[i]+1) result += gcd(A[i],j) - 1;
  //   cout << result << endl;
  // }

  Sieve s;
  ll result = 0;
  rep(i,M) {
    vector<p_ll> factors = s.factors(A[i]);
    ll nowres = A[i];
    // for (auto x: factors) cout << x.first << "^" << x.second << " "; cout << endl;
    for (auto x: factors) nowres = nowres/x.first * ((x.first-1)*(x.second+1)+1);
    nowres -= A[i];
    // cout << nowres << endl;
    result += nowres;
  }
  cout << result << endl;
  return 0;
}
0