#include using namespace std; #define ii pair #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC #define debug(x) std::cout << #x << ": " << x << '\n'; const int N = 1e6+7; int pw[N]; bool p[N]; vector d[N]; bool used[N]; int me[N]; int cnt[N]; signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20); #endif for (int i = 1; i < N; ++i) for (int j = i; j < N; j += i) d[j].app(i); for (int i = 2; i < N; ++i) p[i] = 1; for (int i = 2; i < N; ++i) { if (p[i]) { pw[i] = 1; for (int j = i * 2; j < N; j += i) { p[j] = 0; pw[j]++; } } } for (int i = 0; i < N; ++i) { reverse(all(d[i])); } int n, m; cin >> n >> m; ll ans = 0; for (int i = 0; i < m; ++i) { int x; cin >> x; if (used[x]) { ans += me[x]; continue; } used[x] = 1; for (int a : d[x]) cnt[a] = 0; for (int a : d[x]) { cnt[a] += x/a; me[x] += cnt[a] * ((x - 1) % a); for (int b : d[a]) if (b < a) cnt[b] -= cnt[a]; } ans += me[x]; } cout << ans << endl; #ifdef HOME cout << Time << endl; #endif }