結果

問題 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  
実行時間 833 ms / 2,000 ms
コード長 1,267 bytes
コンパイル時間 2,355 ms
コンパイル使用メモリ 194,400 KB
実行使用メモリ 83,968 KB
最終ジャッジ日時 2024-04-25 10:02:05
合計ジャッジ時間 21,386 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 677 ms
83,840 KB
testcase_01 AC 431 ms
83,840 KB
testcase_02 AC 549 ms
83,840 KB
testcase_03 AC 174 ms
83,712 KB
testcase_04 AC 268 ms
83,968 KB
testcase_05 AC 56 ms
83,840 KB
testcase_06 AC 55 ms
83,840 KB
testcase_07 AC 211 ms
83,712 KB
testcase_08 AC 184 ms
83,840 KB
testcase_09 AC 468 ms
83,840 KB
testcase_10 AC 434 ms
83,840 KB
testcase_11 AC 471 ms
83,840 KB
testcase_12 AC 439 ms
83,840 KB
testcase_13 AC 532 ms
83,712 KB
testcase_14 AC 539 ms
83,712 KB
testcase_15 AC 512 ms
83,968 KB
testcase_16 AC 515 ms
83,840 KB
testcase_17 AC 528 ms
83,840 KB
testcase_18 AC 56 ms
83,840 KB
testcase_19 AC 56 ms
83,840 KB
testcase_20 AC 58 ms
83,840 KB
testcase_21 AC 58 ms
83,712 KB
testcase_22 AC 505 ms
83,840 KB
testcase_23 AC 386 ms
83,712 KB
testcase_24 AC 536 ms
83,712 KB
testcase_25 AC 489 ms
83,840 KB
testcase_26 AC 501 ms
83,840 KB
testcase_27 AC 57 ms
83,840 KB
testcase_28 AC 56 ms
83,712 KB
testcase_29 AC 55 ms
83,968 KB
testcase_30 AC 55 ms
83,968 KB
testcase_31 AC 56 ms
83,712 KB
testcase_32 AC 56 ms
83,840 KB
testcase_33 AC 55 ms
83,712 KB
testcase_34 AC 56 ms
83,840 KB
testcase_35 AC 56 ms
83,840 KB
testcase_36 AC 55 ms
83,584 KB
testcase_37 AC 56 ms
83,840 KB
testcase_38 AC 537 ms
83,840 KB
testcase_39 AC 630 ms
83,840 KB
testcase_40 AC 383 ms
83,712 KB
testcase_41 AC 725 ms
83,712 KB
testcase_42 AC 723 ms
83,840 KB
testcase_43 AC 811 ms
83,968 KB
testcase_44 AC 833 ms
83,840 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