結果

問題 No.1036 Make One With GCD 2
ユーザー TonalidadeHidricaTonalidadeHidrica
提出日時 2020-04-24 21:57:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 760 ms / 2,000 ms
コード長 1,267 bytes
コンパイル時間 1,877 ms
コンパイル使用メモリ 197,816 KB
実行使用メモリ 83,816 KB
最終ジャッジ日時 2023-08-07 16:20:58
合計ジャッジ時間 18,332 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 628 ms
83,604 KB
testcase_01 AC 351 ms
83,600 KB
testcase_02 AC 431 ms
83,524 KB
testcase_03 AC 107 ms
83,596 KB
testcase_04 AC 194 ms
83,776 KB
testcase_05 AC 22 ms
83,516 KB
testcase_06 AC 22 ms
83,584 KB
testcase_07 AC 152 ms
83,588 KB
testcase_08 AC 120 ms
83,508 KB
testcase_09 AC 379 ms
83,516 KB
testcase_10 AC 350 ms
83,504 KB
testcase_11 AC 386 ms
83,524 KB
testcase_12 AC 355 ms
83,816 KB
testcase_13 AC 459 ms
83,668 KB
testcase_14 AC 467 ms
83,588 KB
testcase_15 AC 438 ms
83,592 KB
testcase_16 AC 440 ms
83,600 KB
testcase_17 AC 453 ms
83,572 KB
testcase_18 AC 22 ms
83,532 KB
testcase_19 AC 22 ms
83,532 KB
testcase_20 AC 22 ms
83,620 KB
testcase_21 AC 24 ms
83,592 KB
testcase_22 AC 433 ms
83,516 KB
testcase_23 AC 316 ms
83,524 KB
testcase_24 AC 456 ms
83,552 KB
testcase_25 AC 410 ms
83,508 KB
testcase_26 AC 425 ms
83,600 KB
testcase_27 AC 22 ms
83,508 KB
testcase_28 AC 22 ms
83,548 KB
testcase_29 AC 21 ms
83,596 KB
testcase_30 AC 22 ms
83,524 KB
testcase_31 AC 22 ms
83,636 KB
testcase_32 AC 21 ms
83,528 KB
testcase_33 AC 21 ms
83,516 KB
testcase_34 AC 22 ms
83,572 KB
testcase_35 AC 21 ms
83,664 KB
testcase_36 AC 22 ms
83,600 KB
testcase_37 AC 22 ms
83,512 KB
testcase_38 AC 430 ms
83,512 KB
testcase_39 AC 570 ms
83,600 KB
testcase_40 AC 320 ms
83,516 KB
testcase_41 AC 671 ms
83,672 KB
testcase_42 AC 649 ms
83,600 KB
testcase_43 AC 745 ms
83,512 KB
testcase_44 AC 760 ms
83,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

constexpr int N = 512345, M = 20;
ll a[N][M];

int main(){
	int n; scanf("%d", &n);
	REP(i, n) scanf("%lld", a[i]);
	FOR(i, n, N) a[i][0] = 1;
	FOR(i, 1, M){
		REP(j, n){
			int k = j + (1<<(i-1));
			if(k >= N) continue;
			a[j][i] = gcd(a[j][i-1], a[k][i-1]);
		}
	}
	DEBUG("constructed\n");
	ll ans = 0;
	REP(i, n){
		ll z = 0;
		int j = i;
		for(int k = M-1; k >= 0; k--){
			int jj = j + (1<<k);
			if(jj > n) continue;
			ll zz = gcd(z, a[j][k]);
			DEBUG("  gcd[%d, %d) = %lld -> %lld\n", j, jj, a[j][k], z);
			if(zz > 1) {
				j = jj;
				z = zz;
			}
		}
		DEBUG("[%d, %d)\n", i, j);
		ans += n-j;
	}
	printf("%lld\n", ans);
}
0