|
发表于 2021-3-5 08:26:28
|
显示全部楼层
回帖奖励 +1 鱼币
答案:1739023853137
- /*
- 答案:1739023853137
- 耗时:1.63907秒
- */
- #include <iostream>
- #include <cstring>
- #include <omp.h>
- using namespace std;
- bool a[100000001];
- bool b[100000001];
- int main(void)
- {
- double t = omp_get_wtime();
- long long ans = 0;
- //素数打表开始
- memset(a, 1, sizeof(a));
- memset(b, 1, sizeof(b));
- a[1] = false;
- for (long long i = 2; i <= 10000; i++)
- {
- if (a[i] == true)
- for (long long j = i; i*j <= 100000000; j++)
- a[j * i] = false;
- }
- //素数打表结束
- #pragma omp parallel for reduction(+: ans) shared(b) schedule(guided)
- for (long long x = 1; x <= 100000000; x++)
- {
- b[x] = true;
- if (x != 1 && x % 2 == 1)//排除奇数
- continue;
- for (long long y = 1; y <= x / y; y++)
- {
- if (x%y == 0 && a[y + x / y] == false)
- {
- b[x] = false;
- break;
- }
- }
- if (b[x] == true)
- ans = ans + x;
- }
- t = omp_get_wtime() - t;
- cout << ans << endl << t << endl;
- return 0;
- }
复制代码 |
|