Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define debug(l) cerr<<#l<<' '<<l<<'\n';
- #include "bits/stdc++.h"
- using namespace std;
- #define all(a) a.begin(), a.end()
- typedef long long ll;
- typedef pair<ll, ll> pll;
- typedef long double ld;
- constexpr int N = 1e9 / 3 + 2;
- bitset<N> b;
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n, x;
- cin >> n >> x;
- int ans = 0;
- ans = ans * x + 2;
- ans = ans * x + 3;
- for (int i = 5; i <= n; i++) {
- if (i % 6 != 1 && i % 6 != 5) {
- continue;
- }
- int k = (i / 6) * 2 + (i % 6 == 5 ? 1 : 0);
- if (!b[k]) {
- ans = ans * x + i;
- if (i * 1ll * i <= n) {
- for (ll j = i * i; j <= n; j += i) {
- if (j % 6 != 1 && j % 6 != 5)continue;
- int k2 = (j / 6) * 2 + (j % 6 == 5 ? 1 : 0);
- b[k2] = 1;
- }
- }
- }
- }
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement