-
Notifications
You must be signed in to change notification settings - Fork 67
/
ADAGF.cpp
63 lines (56 loc) · 1.17 KB
/
ADAGF.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// main.cpp
// Dolphin
//
// Created by Mahmud on 3/07/17.
// Copyright © 2017 Mahmud. All rights reserved.
//
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <utility>
#include <cassert>
#include <iomanip>
#include <ctime>
#include <sstream>
#include <istream>
using namespace std;
const int me = 300025;
int N;
int a[me];
map<int, int> lengths;
int main() {
//ios_base::sync_with_stdio(0);
//cin.tie(0);
scanf("%d", &N);
for(int i = 1; i <= N; i ++){
scanf("%d", &a[i]);
}
long long result = 0;
for(int i = 1; i <= N; i ++){
map<int, int> new_lengths;
for(auto j : lengths){
int to = __gcd(a[i], j.first);
new_lengths[to] += j.second;
}
new_lengths[a[i]] ++;
lengths = new_lengths;
for(auto j : lengths){
result += 1LL * j.first * j.second;
}
}
cout << result << endl;
return 0;
}