結果
| 問題 |
No.1514 Squared Matching
|
| コンテスト | |
| ユーザー |
tkmst201
|
| 提出日時 | 2021-07-04 10:43:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,468 bytes |
| コンパイル時間 | 2,251 ms |
| コンパイル使用メモリ | 195,548 KB |
| 最終ジャッジ日時 | 2025-01-22 17:30:28 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 TLE * 16 |
ソースコード
#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];
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; cur /= spf[cur]) {
if (prv != spf[cur]) {
if (o) p *= prv;
prv = spf[cur];
o = true;
}
else o ^= 1;
}
if (o) p *= prv;
if (p > N) continue;
ans += cnt[N / p];
}
cout << ans << endl;
}
tkmst201