結果

問題 No.1514 Squared Matching
ユーザー tkmst201tkmst201
提出日時 2021-07-04 10:47:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,348 bytes
コンパイル時間 2,111 ms
コンパイル使用メモリ 202,324 KB
実行使用メモリ 787,488 KB
最終ジャッジ日時 2023-09-13 15:44:29
合計ジャッジ時間 8,297 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 MLE -
testcase_02 AC 15 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 37 ms
15,080 KB
testcase_07 AC 614 ms
152,280 KB
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 AC 640 ms
159,268 KB
testcase_23 AC 1,414 ms
315,492 KB
testcase_24 AC 2,314 ms
472,172 KB
testcase_25 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 998244353;
constexpr bool debug = false;
//---------------------------------//

std::vector<int> sieve_smallest_prime_factor(int n) {
	assert(n >= 0);
	std::vector<int> res(n + 1);
	std::iota(begin(res), end(res), 0);
	
	for (int i = 2; i * i <= n; ++i) {
		if (res[i] < i) continue;
		for (int j = i * i; j <= n; j += i) {
			if (res[j] == j) res[j] = i;
		}
	}
	
	return res;
}

int main() {
	int N;
	cin >> N;
	auto spf = sieve_smallest_prime_factor(N);
	
	vector<int> cnt(N + 1);
	FOR(i, 1, N + 1) {
		if (i * i > N) break;
		++cnt[i * i];
	}
	REP(i, N) cnt[i + 1] += cnt[i];
	
	vector<ll> pv(N + 1, 1);
	ll ans = 0;
	FOR(i, 1, N + 1) {
		const int d = spf[i];
		if (pv[i / d] % d == 0) pv[i] = pv[i / d] / d;
		else pv[i] = pv[i / d] * d;
		if (pv[i] > N) continue;
		ans += cnt[N / pv[i]];
	}
	cout << ans << endl;
}
0