UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#196949#2853. 环 cycletkswls1001017ms20024kbC++111.7kb2023-11-04 09:22:572023-11-04 12:09:23

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, a[100005], sum[100005], f[100005], st[100005][21], ans;
const int mod = 1000000007;
inline int query(int l, int r) {
	int mid = (log2(r - l + 1));
//	cout << l << " " << r << ' ' << __gcd(st[l][mid], st[r - (1 << mid) + 1][mid]) << " " << mid << "&&&&&\n";
	return __gcd(st[l][mid], st[r - (1 << mid) + 1][mid]);
}
inline void calc(int end) {
	memset(f, 0, sizeof(f));
	memset(sum, 0, sizeof(sum));
	f[0] = sum[0] = 1;
	int l, r, mid;
//	cout << end << "[]\n";
	for (int i = 1; i <= end; i++) {
		l = 1, r = i;
		while (l < r) {
			mid = (l + r) >> 1;
			if (query(mid, i) != 1) r = mid;
			else l = mid + 1;
		}
		if ((l == 1)) {
			f[i] = sum[i - 1];
		} else {
			f[i] = sum[i - 1] - sum[l - 2] + mod;
			f[i] %= mod;
		}
		sum[i] = sum[i - 1] + f[i];
		sum[i] %= mod;
//		cout << f[i] << " " << sum[i] << " " << l << "|";
	}
//	cout << endl;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		st[i][0] = a[i];
	}
	for (int i = 1; (1 << i) <= n; i++) {
		for (int j = 1; j + (1 << i) - 1 <= n; j++) {
			st[j][i] = __gcd(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]);
//			cout << i << " " << j << " " << st[i][j] << "()\n";
		}
	}
	int lst = -1;
	for (int i = n + 1; i >= 2; i--) {
		if (i <= n) {
			a[1] = __gcd(a[i], a[1]);
		}
		if (a[1] == 1) break;
		if (a[1] != lst) {
			st[1][0] = a[1];
			for (int j = 1; (1 << j) <= n; j++) {
				st[1][j] = __gcd(st[1][j - 1], st[1 + (1 << (j - 1))][j - 1]);
			}
			calc(i - 1);
			lst = a[1];
		}
		ans += f[i - 1];
		ans %= mod;
	}
	cout << ans;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 20
Accepted
time: 0ms
memory: 2860kb

input:

100
2689450 68725375 26949485 11087687 2644252 6175548 67879809 15576083 4367079 22420620 51754480 3...

output:

328118928

result:

ok single line: '328118928'

Test #2:

score: 20
Accepted
time: 0ms
memory: 2856kb

input:

100
90152000 131081008 121499875 601138125 494471250 548721810 99292518 37691307 28064691 122598387 ...

output:

325447573

result:

ok single line: '325447573'

Test #3:

score: 20
Accepted
time: 70ms
memory: 6280kb

input:

20000
249246704 67182400 23547600 28179000 5213115 16013045 17344823 468310221 217488294 86677236 63...

output:

469407434

result:

ok single line: '469407434'

Test #4:

score: 20
Accepted
time: 495ms
memory: 20020kb

input:

100000
74940936 43089140 2 7836660 4492782 2257794 14918904 75867064 40425582 18651441 31863401 1913...

output:

998385344

result:

ok single line: '998385344'

Test #5:

score: 20
Accepted
time: 452ms
memory: 20024kb

input:

100000
410848080 272410140 300376200 502572900 104634030 95373317 65965705 140242050 2122200 2744280...

output:

374743532

result:

ok single line: '374743532'

Extra Test:

score: 0
Extra Test Passed