結果

問題 No.1514 Squared Matching
ユーザー nok0nok0
提出日時 2021-04-29 20:18:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,325 ms / 4,000 ms
コード長 1,587 bytes
コンパイル時間 2,293 ms
コンパイル使用メモリ 205,064 KB
実行使用メモリ 214,932 KB
最終ジャッジ日時 2023-09-24 21:11:31
合計ジャッジ時間 43,209 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 579 ms
214,932 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 109 ms
6,384 KB
testcase_07 AC 1,603 ms
45,060 KB
testcase_08 AC 1,970 ms
207,816 KB
testcase_09 AC 787 ms
184,212 KB
testcase_10 AC 1,479 ms
197,928 KB
testcase_11 AC 1,834 ms
205,204 KB
testcase_12 AC 2,178 ms
210,368 KB
testcase_13 AC 2,211 ms
213,236 KB
testcase_14 AC 2,261 ms
214,092 KB
testcase_15 AC 2,319 ms
214,532 KB
testcase_16 AC 2,324 ms
214,924 KB
testcase_17 AC 2,301 ms
214,900 KB
testcase_18 AC 2,296 ms
214,928 KB
testcase_19 AC 2,294 ms
214,932 KB
testcase_20 AC 2,325 ms
214,884 KB
testcase_21 AC 2,286 ms
214,732 KB
testcase_22 AC 1,678 ms
47,892 KB
testcase_23 AC 1,906 ms
89,628 KB
testcase_24 AC 2,051 ms
128,492 KB
testcase_25 AC 2,215 ms
176,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#pragma region Math Osa_k
struct osa_k {
private:
	std::vector<int> spf, pr;

public:
	osa_k() = default;

	osa_k(int MAX) : spf(MAX + 1) {
		for(int i = 2; i <= MAX; i++) {
			if(spf[i] == 0) {
				spf[i] = i;
				pr.push_back(i);
			}
			for(int j = 0; j < pr.size() and pr[j] <= spf[i] and i * pr[j] <= MAX; j++)
				spf[i * pr[j]] = pr[j];
		}
	}

	std::vector<std::pair<int, int>> prime_factorization(int n) {
		std::vector<std::pair<int, int>> divisor;
		if(n == 1) return divisor;
		int before = spf[n], cnt = 0;
		while(n > 1) {
			if(spf[n] == before) {
				cnt++;
				n /= spf[n];
			} else {
				divisor.emplace_back(before, cnt);
				before = spf[n];
				cnt = 1;
				n /= spf[n];
			}
		}
		divisor.emplace_back(before, cnt);
		return divisor;
	}

	int smallestprimefactor(const int n) const {
		return spf[n];
	}

	bool is_prime(const int n) const {
		return n == spf[n];
	}
};
#pragma endregion

int embed[6] = {0, 99371160, 207162592, 318140852, 431159896, 545761220};

int n, res;
int main() {
	scanf("%d", &n);
	osa_k pf(n);

	/*
	愚直
	for(int a = 1; a <= n; a++) {
		auto v = pf.prime_factorization(a);
		int b = 1;
		for(auto [val, cnt] : v)
			if(cnt & 1) b *= val;
		res += sqrt(n / b);
	}
	printf("%d\n", res);
	*/

	int base = n / 10000000 * 10000000;
	res = embed[n / 10000000];
	for(int a = base + 1; a <= n; a++) {
		auto v = pf.prime_factorization(a);
		int b = 1;
		for(auto [val, cnt] : v)
			if(cnt & 1) b *= val;
		int d = sqrt(n / b);
		res += d + min(d, (int)sqrt(base / b));
	}

	printf("%d\n", res);
}
0