結果

問題 No.1514 Squared Matching
ユーザー tkmst201tkmst201
提出日時 2021-07-04 10:23:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,546 bytes
コンパイル時間 1,994 ms
コンパイル使用メモリ 201,720 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-09-13 15:24:41
合計ジャッジ時間 8,923 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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> sq; // N 以下の平方数
	FOR(i, 1, N + 1) {
		if (i * i > N) break;
		sq.emplace_back(i * i);
	}
	
	ll ans = 0;
	FOR(i, 1, N + 1) {
		ll p = 1; // i * p が平方数となる最小の p
		int prv = -1, o = false;
		for (int cur = i; cur > 1;) {
			if (prv != spf[cur]) {
				if (o) p *= prv;
				prv = spf[cur];
				o = true;
			}
			else o ^= 1;
			cur /= spf[cur];
		}
		if (o) p *= prv;
		if (p > N) break;
		
		// pd <= x となる d の最大値(d は平方数)
		ans += upper_bound(ALL(sq), N / p) - sq.begin();
	}
	cout << ans << endl;
}
0