結果

問題 No.3691 Calculate Mu Sum
コンテスト
ユーザー KEYBO
提出日時 2026-09-06 19:37:04
言語 C++23(gnu拡張gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=gnu++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 203 ms / 2,000 ms
+ 778µs
コード長 1,059 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,382 ms
コンパイル使用メモリ 386,500 KB
実行使用メモリ 43,648 KB
最終ジャッジ日時 2026-09-06 19:37:21
合計ジャッジ時間 8,112 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

using ll = int64_t;
using ul = uint64_t;
using ld = long double;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvd = vector<vd>;
using vvc = vector<vc>;
using vvb = vector<vb>;
using vvl = vector<vl>;
using mint = modint998244353;
using vm = vector<mint>;

// エラトステネスの篩みたいにやるのか

void sieve(int N, vb &del) {
  for (int p = 2; p*p <= N; p++) {
    if (del[p]) continue;
    for (int a = p*p; a <= N; a += p) {
      del[a] = true;
    }
  }
  return;
}

int main() {
  int N;
	cin >> N;
	vb del(N + 1, false);
	sieve(N, del);
	vi mu(N + 1, 1);
	for (int a = 2; a <= N; a++) {
		if (del[a]) continue;
		for (int b = 1; a*b <= N; b++) {
			if (b%a == 0) mu[a*b] = 0;
			else mu[a*b] *= -1;
		}
	}
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		ans += mu[i];
	}
	cout << ans << endl;
  return 0;
}
0