-
[6359] 만취한 상범BOJ 2022. 2. 26. 09:39
https://www.acmicpc.net/problem/6359
6359번: 만취한 상범
한 줄에 한 개씩 각 테스트 케이스의 답, 즉 몇 명이 탈출할 수 있는지를 출력한다.
www.acmicpc.net
2중 for로 일일히 토글하면서 시뮬레이션했다.
#include <bits/stdc++.h>using namespace std;#ifdef ONLINE_JUDGEconstexpr bool local = false;#elseconstexpr bool local = true;#endifusing ll = long long;using pi = pair<ll, ll>;int t, n, a[105];int main(void) {if (!local) ios_base::sync_with_stdio(0), cin.tie(0);cin >> t;while (t--) {cin >> n;memset(a, 0, sizeof(a));int i, j;for (i = 1; i <= n; i++)for (j = i; j <= n; j += i) a[j] ^= 1;cout << accumulate(a + 1, a + n + 1, 0) << '\n';}return 0;}
'BOJ' 카테고리의 다른 글
[2696] 중앙값 구하기 (0) 2022.02.27 [5052] 전화번호 목록 (0) 2022.02.27 [1727] 커플 만들기 (0) 2022.02.25 [13904] 과제 (0) 2022.02.25 [1455] 뒤집기 II (0) 2022.02.24