結果

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vp = vector<pair<int, int>>;

#define rep(i, s, n) for (int i = s; i < (int)(n); i++)
#define sz(x) ((int)(x).size())
constexpr int INFI = 1001001001;
constexpr ll INFL = (1LL << 60);

vl get_primes(ll n) {
	ll limit = sqrt(n) + 1;
	vector<bool> is_prime(limit + 1, true);
	is_prime[0] = is_prime[1] = false;

	for (ll i = 2; i * i <= limit; i++) {
		if (!is_prime[i]) continue;
		for (ll j = i * i; j <= limit; j += i){
			is_prime[j] = false;
		}
	}

	vl primes;
	for (ll i = 2; i <= limit; i++){
		if (is_prime[i]) primes.push_back(i);
	}
	return primes;
}

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

	// input
	ll n, ans = 0;
	cin >> n;

	vl primes = get_primes(n);

	for (auto x : primes){
		ll temp = x;
		while(true){
			temp *= x;
			if(temp <= n){
				ans += temp;
			}
			else break;
		}
	}
	cout << ans << endl;
	return 0;
}
0