Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 투 포인터
- 스택
- 그리디 알고리즘
- c++
- 정렬
- 구현
- Unreal Engine 5
- 재귀
- 문자열
- 우선순위 큐
- BFS
- 유니티
- 자료구조
- 다이나믹 프로그래밍
- 트리
- XR Interaction Toolkit
- 누적 합
- 그래프
- Team Fortress 2
- 백트래킹
- 시뮬레이션
- 알고리즘
- 다익스트라
- ue5
- VR
- DFS
- 수학
- 브루트포스
- 유니온 파인드
- 백준
Archives
- Today
- Total
1일1알
백준 2777번 숫자 놀이 C++ 본문
한 자리수 중 가장 큰 수인 9부터 2까지의 곱으로 나타낼 수 있는지 확인하고 가능하다면 그 개수를 출력하고, 가능하지 않다면 -1을 출력한다. 1은 따로 처리해 주었다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t, n;
cin >> t;
while (t--) {
cin >> n;
if (n == 1) {
cout << 1 << "\n";
continue;
}
vector<int> factors;
int div = 9;
while (div > 1) {
if (n % div == 0) {
n /= div;
factors.push_back(div);
}
else {
div--;
}
}
if (n == 1) cout << factors.size() << "\n";
else cout << -1 << "\n";
}
};
'알고리즘' 카테고리의 다른 글
백준 10431번 줄세우기 C++ (0) | 2022.01.31 |
---|---|
백준 1491번 나선 C++ (0) | 2022.01.30 |
백준 8980번 택배 C++ (0) | 2022.01.28 |
백준 1083번 소트 C++ (0) | 2022.01.27 |
백준 1092번 배 C++ (0) | 2022.01.26 |