結果
問題 | No.1262 グラフを作ろう! |
ユーザー | sak |
提出日時 | 2020-11-28 19:19:21 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 639 ms / 3,000 ms |
コード長 | 2,763 bytes |
コンパイル時間 | 2,699 ms |
コンパイル使用メモリ | 212,468 KB |
実行使用メモリ | 34,584 KB |
最終ジャッジ日時 | 2024-09-12 23:26:35 |
合計ジャッジ時間 | 44,455 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 493 ms
33,712 KB |
testcase_01 | AC | 376 ms
31,388 KB |
testcase_02 | AC | 547 ms
33,364 KB |
testcase_03 | AC | 496 ms
34,180 KB |
testcase_04 | AC | 69 ms
27,120 KB |
testcase_05 | AC | 266 ms
30,056 KB |
testcase_06 | AC | 58 ms
26,932 KB |
testcase_07 | AC | 85 ms
27,360 KB |
testcase_08 | AC | 340 ms
30,944 KB |
testcase_09 | AC | 342 ms
31,864 KB |
testcase_10 | AC | 257 ms
30,064 KB |
testcase_11 | AC | 432 ms
31,024 KB |
testcase_12 | AC | 517 ms
33,352 KB |
testcase_13 | AC | 500 ms
34,196 KB |
testcase_14 | AC | 263 ms
29,692 KB |
testcase_15 | AC | 278 ms
31,108 KB |
testcase_16 | AC | 353 ms
31,208 KB |
testcase_17 | AC | 371 ms
31,072 KB |
testcase_18 | AC | 546 ms
33,572 KB |
testcase_19 | AC | 102 ms
27,296 KB |
testcase_20 | AC | 222 ms
28,768 KB |
testcase_21 | AC | 594 ms
34,216 KB |
testcase_22 | AC | 58 ms
26,920 KB |
testcase_23 | AC | 331 ms
31,212 KB |
testcase_24 | AC | 385 ms
31,360 KB |
testcase_25 | AC | 103 ms
27,312 KB |
testcase_26 | AC | 138 ms
27,824 KB |
testcase_27 | AC | 230 ms
29,472 KB |
testcase_28 | AC | 224 ms
28,972 KB |
testcase_29 | AC | 153 ms
28,028 KB |
testcase_30 | AC | 202 ms
28,848 KB |
testcase_31 | AC | 592 ms
34,336 KB |
testcase_32 | AC | 350 ms
30,800 KB |
testcase_33 | AC | 172 ms
29,052 KB |
testcase_34 | AC | 285 ms
29,828 KB |
testcase_35 | AC | 460 ms
33,268 KB |
testcase_36 | AC | 182 ms
29,528 KB |
testcase_37 | AC | 562 ms
34,140 KB |
testcase_38 | AC | 291 ms
30,304 KB |
testcase_39 | AC | 307 ms
31,124 KB |
testcase_40 | AC | 272 ms
30,260 KB |
testcase_41 | AC | 175 ms
28,584 KB |
testcase_42 | AC | 477 ms
32,528 KB |
testcase_43 | AC | 255 ms
29,696 KB |
testcase_44 | AC | 314 ms
30,228 KB |
testcase_45 | AC | 438 ms
31,820 KB |
testcase_46 | AC | 128 ms
27,876 KB |
testcase_47 | AC | 340 ms
32,568 KB |
testcase_48 | AC | 386 ms
31,688 KB |
testcase_49 | AC | 520 ms
33,800 KB |
testcase_50 | AC | 432 ms
32,204 KB |
testcase_51 | AC | 371 ms
32,572 KB |
testcase_52 | AC | 142 ms
28,316 KB |
testcase_53 | AC | 108 ms
27,856 KB |
testcase_54 | AC | 533 ms
34,112 KB |
testcase_55 | AC | 369 ms
31,880 KB |
testcase_56 | AC | 169 ms
28,556 KB |
testcase_57 | AC | 578 ms
34,204 KB |
testcase_58 | AC | 471 ms
33,428 KB |
testcase_59 | AC | 173 ms
28,428 KB |
testcase_60 | AC | 570 ms
33,896 KB |
testcase_61 | AC | 233 ms
29,648 KB |
testcase_62 | AC | 514 ms
33,472 KB |
testcase_63 | AC | 513 ms
34,268 KB |
testcase_64 | AC | 341 ms
31,208 KB |
testcase_65 | AC | 102 ms
27,584 KB |
testcase_66 | AC | 239 ms
29,672 KB |
testcase_67 | AC | 167 ms
28,620 KB |
testcase_68 | AC | 107 ms
27,564 KB |
testcase_69 | AC | 183 ms
28,820 KB |
testcase_70 | AC | 382 ms
31,428 KB |
testcase_71 | AC | 389 ms
31,448 KB |
testcase_72 | AC | 517 ms
32,536 KB |
testcase_73 | AC | 639 ms
34,488 KB |
testcase_74 | AC | 437 ms
33,720 KB |
testcase_75 | AC | 461 ms
32,364 KB |
testcase_76 | AC | 385 ms
31,176 KB |
testcase_77 | AC | 468 ms
33,048 KB |
testcase_78 | AC | 419 ms
31,816 KB |
testcase_79 | AC | 544 ms
33,492 KB |
testcase_80 | AC | 359 ms
31,072 KB |
testcase_81 | AC | 435 ms
32,976 KB |
testcase_82 | AC | 606 ms
34,360 KB |
testcase_83 | AC | 417 ms
31,100 KB |
testcase_84 | AC | 417 ms
31,236 KB |
testcase_85 | AC | 621 ms
34,112 KB |
testcase_86 | AC | 535 ms
32,828 KB |
testcase_87 | AC | 612 ms
33,788 KB |
testcase_88 | AC | 434 ms
33,116 KB |
testcase_89 | AC | 414 ms
30,848 KB |
testcase_90 | AC | 413 ms
34,400 KB |
testcase_91 | AC | 397 ms
34,552 KB |
testcase_92 | AC | 388 ms
34,460 KB |
testcase_93 | AC | 486 ms
34,548 KB |
testcase_94 | AC | 540 ms
34,508 KB |
testcase_95 | AC | 557 ms
34,584 KB |
ソースコード
#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; }