Advertisement
ivnikkk

Untitled

May 26th, 2022
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define debug(l) cerr<<#l<<' '<<l<<'\n';
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5. #define all(a) a.begin(), a.end()
  6. typedef long long ll;
  7. typedef pair<ll, ll> pll;
  8. typedef long double ld;
  9. constexpr int N = 1e9 / 3 + 2;
  10. bitset<N> b;
  11. signed main() {
  12. #ifdef _DEBUG
  13.     freopen("input.txt", "r", stdin);
  14.     freopen("output.txt", "w", stdout);
  15. #endif
  16.     ios_base::sync_with_stdio(false);
  17.     cin.tie(nullptr);
  18.     cout.tie(nullptr);
  19.     int n, x;
  20.     cin >> n >> x;
  21.     int ans = 0;
  22.     ans = ans * x + 2;
  23.     ans = ans * x + 3;
  24.     for (int i = 5; i <= n; i++) {
  25.         if (i % 6 != 1 && i % 6 != 5) {
  26.             continue;
  27.         }
  28.         int k = (i / 6) * 2 + (i % 6 == 5 ? 1 : 0);
  29.         if (!b[k]) {
  30.             ans = ans * x + i;
  31.             if (i * 1ll * i <= n) {
  32.                 for (ll j = i * i; j <= n; j += i) {
  33.                     if (j % 6 != 1 && j % 6 != 5)continue;
  34.                     int k2 = (j / 6) * 2 + (j % 6 == 5 ? 1 : 0);
  35.                     b[k2] = 1;
  36.                 }
  37.             }
  38.         }
  39.     }
  40.     cout << ans << '\n';
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement