結果

問題 No.1036 Make One With GCD 2
コンテスト
ユーザー _a muni
提出日時 2026-04-10 23:50:09
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 852 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,322 ms
コンパイル使用メモリ 339,444 KB
実行使用メモリ 89,520 KB
最終ジャッジ日時 2026-04-10 23:50:30
合計ジャッジ時間 17,388 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(void) {
	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];

	int lg = 20;
	vector<vector<ll>> table(lg, vector<ll>(n));
	for(int i = 0; i < n; i++) table[0][i] = a[i];

	// cerr << 1 << endl;

	for(int j = 0; j+1 < lg; j++) {
		for(int i = 0; i+(1<<(j+1)) <= n; i++) {
			table[j+1][i] = gcd(table[j][i], table[j][i+(1<<j)]);
		}
	}

	// cerr << 2 << endl;

	// prod gcd[l, r)
	auto prod = [&](int l, int r) {
		int k = 63 - __builtin_clzll((ll)(r-l));
		return gcd(table[k][l], table[k][r-(1<<k)]);
	};

	int ans = 0;

	int r = 0;
	for(int l = 0; l < n; l++) {
		if(r < l) r = l;

		// cerr << r << " " << l << endl;
		while(r < n && prod(l, r+1) != 1) {
			r++;
		}

		ans += r-l;
	}

	//cout << ans << endl;
	cout << n*(n+1)/2 - ans << endl;
}
0