結果
問題 |
No.3296 81-like number
|
ユーザー |
![]() |
提出日時 | 2025-10-05 14:13:50 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,754 bytes |
コンパイル時間 | 5,347 ms |
コンパイル使用メモリ | 335,312 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-10-05 14:14:04 |
合計ジャッジ時間 | 6,142 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using mint = atcoder::modint998244353; // using mint = double; #define rep(i, l, r) for (int i = (int)(l); i<(int)(r); i++) #define ll long long #define ld long double #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define siz(x) (int)(x).size() template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } const int inf = 1e9; const ll INF = 4e18; template<class T> using pq = priority_queue<T, vector<T>, less<T>>; template<class T> using spq = priority_queue<T, vector<T>, greater<T>>; vector<int> di = {0, 0, 1, -1}; vector<int> dj = {1, -1, 0, 0}; struct Edge { int to, cost; }; //エラトステネスの篩による [1, N] の素数判定 vector<bool> primeSieve(int N) { vector<bool> isPrime(N+1, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i <= N; i++) { if (isPrime[i]) { for (int j = 2*i; j <= N; j += i) isPrime[j] = false; } } return isPrime; } void solve() { ll N; cin >> N; int M = 100050; vector<bool> isprime = primeSieve(M); vector<ll> ans; rep(i, 1, M+1) { if (!isprime[i]) continue; ll now = (ll)i * i; while(now <= N) { ans.push_back(now); now *= i; } } sort(all(ans)); ans.erase(unique(all(ans)), ans.end()); ll sum = 0; for (ll x : ans) sum += x; cout << sum << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int T = 1; // cin >> T; while(T--) { solve(); } }