結果

問題 No.1036 Make One With GCD 2
ユーザー snrnsidysnrnsidy
提出日時 2021-03-31 21:08:53
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,211 bytes
コンパイル時間 2,878 ms
コンパイル使用メモリ 123,612 KB
実行使用メモリ 23,252 KB
最終ジャッジ日時 2023-08-21 20:31:30
合計ジャッジ時間 9,974 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <unordered_set>
#include <fstream>

using namespace std;

#define PI 3.141592653589793
#define MAX 1000000001
const int Mod = 100000007;

long long int tree[1 << 20];

long long int gcd(long long int a, long long int b)
{
	if (b == 0)
	{
		return a;
	}
	return gcd(b, a % b);
}

long long int update(int nodenum, int start, int end)
{
	if (start == end)
	{
		return tree[nodenum];
	}
	int mid = (start + end) / 2;
	return tree[nodenum] = gcd(update(2 * nodenum, start, mid), update(2 * nodenum + 1, mid + 1, end));
}
long long int find(int from, int to, int nodenum, int start, int end)
{
	if (to < start || end < from)
	{
		return 0;
	}
	if (from <= start && end <= to)
	{
		return tree[nodenum];
	}
	int mid = (start + end) / 2;
	return gcd(find(from, to, 2 * nodenum, start, mid), find(from, to, (2 * nodenum + 1), mid + 1, end));
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int size, n, a, b;

	cin >> n;

	size = ceil(log2(n));
	size = pow(2, size);

	for (int i = 0; i < n; i++)
	{
		cin >> tree[size + i];
	}
	
	update(1, 1, size);
	long long int res = 0;
	for (int i = 1; i <= n; i++)
	{
		if (find(i, n, 1, 1, size) != 1)
		{
			continue;
		}
		long long int lo = i;
		long long int hi = n;
		long long int m = 1e9;
		while (lo <= hi)
		{
			long long int mid = (lo + hi) / 2;
			long long int g = find(i, mid, 1, 1, size);
			//cout << i << ' ' << mid << ' ' << g << '\n';
			if (g == 1)
			{
				m = min(mid, m);
				hi = mid - 1;
			}
			else
			{
				lo = mid + 1;
			}
		}
		if (m == 1e9)
		{
			continue;
		}
		//cout << m << ' ' << i << '\n';
		long long int len = n - m + 1;
		res += len;
	}

	cout << res << '\n';
	return 0;
}
0