Advertisement
ivnikkk

Untitled

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