Project_Euler-10 题解
题目
思路
没有思路,一个线性筛秒了,只不过最近没发博客有点手生哈哈哈哈哈。
代码
/*************************************************************************> Author: Royi > Mail: royi990001@gmail.com > From: > Language: C/C++************************************************************************/#include <bits/stdc++.h>
using namespace std;
using ll = long long;const int MAX_N = 2e6;
const int MAX_M = 1e5 + 50;int arr[MAX_N];
int prime[MAX_N];void init() {for (int i = 2; i <= MAX_N; ++i) {if (!arr[i]) prime[++prime[0]] = i;for (int j = 1; j <= prime[0]; ++j) {if (i * prime[j] > MAX_N) break;arr[i * prime[j]] = 1;if (i % prime[j] == 0) break;}}return ;
}ll solve() {ll ans = 0;for (int i = 1; i <= prime[0]; i++) {ans += prime[i];}return ans;
}int main() {ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);init();ll ans = solve();cout << ans << '\n';return 0;
}