結果

問題 No.1262 グラフを作ろう!
ユーザー saksak
提出日時 2020-11-28 18:47:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,773 bytes
コンパイル時間 4,246 ms
コンパイル使用メモリ 204,908 KB
実行使用メモリ 22,536 KB
最終ジャッジ日時 2023-10-10 00:52:05
合計ジャッジ時間 21,226 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
testcase_94 -- -
testcase_95 -- -
権限があれば一括ダウンロードができます

ソースコード

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 {
  vector<ll> pfac;
  Sieve(ll x=pow(10,6)+10) {
    pfac.resize(x,-1); pfac[0] = 0; pfac[1] = 1;
    for (ll i=2; i*i<=x; i++) {
      if (pfac[i]==-1) {
        for (ll j=2; i*j<=x; j++) {
          if (pfac[i*j]==-1) pfac[i*j] = i;
        }
      }
    }
  }
  bool isp(ll n) { return pfac[n]==-1; }
  vector<p_ll> factors(ll n) {
    vector<p_ll> result;
    ll nf = 0, nc = 0;
    while (!isp(n)) { 
      if (nf!=pfac[n]) {
        if (nf) result.push_back(make_pair(nf,nc));
        nf = pfac[n]; nc = 1;
      }
      else nc++;
      n /= pfac[n];
    }
    if (nf!=n) {
      if (nf) result.push_back(make_pair(nf, nc));
      result.push_back(make_pair(n,1));
    }
    else {
      nc++;
      result.push_back(make_pair(nf, nc));
    }
    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-1)*(x.second+1)+1)/x.first;
    nowres -= A[i];
    // cout << nowres << endl;
    result += nowres;
  }
  cout << result << endl;
  return 0;
}
0