-
[2312] 수 복원하기BOJ 2022. 5. 2. 02:06
https://www.acmicpc.net/problem/2312
2312번: 수 복원하기
첫째 줄에 테스트 케이스의 수가 주어진다. 각 테스트 케이스마다 양의 정수 N (2 ≤ N ≤ 100,000)이 주어진다.
www.acmicpc.net
소인수분해후 인수의 개수를 a[i]에 저장하고, a[i]>0일때 i와 a[i]를 출력하자
#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 a[100001];int main(void) {if (!local) ios_base::sync_with_stdio(0), cin.tie(0);int t;cin >> t;while (t--) {int i, n, e;cin >> n;memset(a, 0, sizeof(a));e = 0;for (i = 2; i * i <= n and n > 1; i++) {while (n % i == 0) {e = max(i, e);a[i]++;n /= i;}}if (n > 1) a[n]++, e = max(n, e);for (i = 2; i <= e; i++)if (a[i] > 0) cout << i << ' ' << a[i] << '\n';}return 0;}
'BOJ' 카테고리의 다른 글
[17485] 진우의 달 여행 (Large) (0) 2022.05.14 [14607] 피자 (Large) (0) 2022.05.13 [1283] 단축키 지정 (0) 2022.05.02 [24445] 알고리즘 수업 - 너비 우선 탐색 2 (0) 2022.05.02 [15967] 에바쿰 (0) 2022.05.02