#include #include using lint = long long; void solve() { int n, m; std::cin >> n >> m; std::vector cnt(n + 1, 0); lint ans = 0; while (m--) { int x; std::cin >> x; ++cnt[x]; ans -= x; } // 畳み込み for (int g = 1; g <= n; ++g) { for (int x = g * 2; x <= n; x += g) { cnt[g] += cnt[x] * x / g; } } // cnt[g]: gcd(a, b) | g なる(a, b)の個数 // 包除 for (int g = n; g >= 1; --g) { for (int x = g * 2; x <= n; x += g) { cnt[g] -= cnt[x]; } ans += cnt[g] * g; } // cnt[g]: gcd(a, b) = g なる(a, b)の個数 std::cout << ans << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }