Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int constexpr maxn = 1e5 + 10;
- int n, a[maxn];
- int main() {
- cin >> n;
- for(int i = 1; i <= n; i++) cin >> a[i];
- vector<int> num[maxn], cnt[maxn];
- for(int i = 1; i <= n; i++) {
- for(int j = 0; j < num[i-1].size(); ++j){
- int x = __gcd(num[i-1][j], a[i]);
- if(!num[i].empty() && x == num[i].back()){
- cnt[i].back() += cnt[i-1][j];
- }else{
- num[i].emplace_back(x);
- cnt[i].emplace_back(cnt[i-1][j]);
- }
- }
- num[i].emplace_back(a[i]);
- cnt[i].emplace_back(1);
- }
- int sum = 0;
- for(int i = 1; i <= n; ++i){
- for(int j = 0; j < num[i].size(); ++j){
- sum += num[i][j] * cnt[i][j];
- }
- }
- cout << sum << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment