結果

問題 No.1514 Squared Matching
ユーザー kyo1
提出日時 2022-06-05 03:53:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 627 bytes
コンパイル時間 2,119 ms
コンパイル使用メモリ 196,804 KB
最終ジャッジ日時 2025-01-29 18:23:37
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 TLE * 17 MLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int64_t> X(N + 1, 0);
  iota(X.begin(), X.end(), 0);
  vector<bool> Y(N + 1, true);
  for (int64_t i = 2; i <= N; i++) {
    if (!Y[i]) continue;
    for (int64_t j = i; j <= N; j += i) {
      while (X[j] % (i * i) == 0) {
        X[j] /= i * i;
      }
      Y[j] = false;
    }
  }
  vector<int64_t> Z(N + 1, 0);
  for (int i = 0; i <= N; i++) {
    Z[X[i]]++;
  }
  int64_t res = 0;
  for (int i = 1; i <= N; i++) {
    res += Z[i] * Z[i];
  }
  cout << res << '\n';
  return 0;
}
0