結果

問題 No.3296 81-like number
ユーザー takumi152
提出日時 2025-10-05 14:16:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 917 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 102,256 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-05 14:16:45
合計ジャッジ時間 1,475 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 998244353;

vector<ll> erathosthenes(ll n) {
  vector<bool> mask(n+1, true);
  mask[0] = false;
  mask[1] = false;
  for (int i = 2; i * i <= n; i++) {
    for (int j = i * i; j <= n; j += i) {
      mask[j] = false;
    }
  }
  vector<ll> prime = {};
  for (int i = 0; i <= n; i++) {
    if (mask[i]) prime.push_back(i);
  }
  return prime;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;

  auto primes = erathosthenes(100000);

  ll ans = 0;
  for (auto &p: primes) {
    auto v = p * p;
    while (v <= n) {
      ans += v;
      v *= p;
    }
  }

  cout << ans << endl;

  return 0;
}
0