[BOJ/C, C++] 단계별로 풀어보기 수학 1

Published: (January 3, 2026 at 04:48 AM EST)
3 min read
Source: Dev.to

Source: Dev.to

진법 변환 (문제 링크)

#include 
#include 
using namespace std;
int main() {
    string N; int B; cin >> N >> B;
    int res = 0;
    for (int i = 0; i 
}
#include 
using namespace std;
int main() {
    int N, B; cin >> N >> B;
    string res = "";
    while (N) {
        int temp = N % B;
        N /= B;
        res = (char)(temp >= 10 ? temp - 10 + 'A' : temp + '0') + res;
    }
    cout 
}
int main() {
    int T; scanf("%d", &T);
    for (int i = 0; i 
}
int main() {
    int T; scanf("%d", &T);
    int coins[] = { 25, 10, 5, 1 };
    while (T--) {
        int C; scanf("%d", &C);
        for (int i = 0; i 
    }
}
int main() {
    int N, n = 2; scanf("%d", &N);
    while (N--) n += n - 1;
    printf("%d", n * n);
}
  • 점이 총 두 개인 1단계부터 시작하므로 초기값 n2로 설정합니다.

풀이 2 (수학적 식 활용)

#include 
#include 
using namespace std;
int main() {
    int N; cin >> N;
    int t = pow(2, N) + 1;
    cout 
}
int main() {
    int N; scanf("%d", &N);
    int i = 1; N--;
    for (; N > 0; i++) N -= 6 * i;
    printf("%d", i);
}
  • 방 번호를 1, 6, 12, …, 6·(n‑1)씩 차감하는 방식으로 해당 방의 단계를 구합니다.

2869번 달팽이는 올라가고 싶다 (문제 링크)

#include 
int main() {
    int A, B, V; scanf("%d %d %d", &A, &B, &V);
    V -= A;               // 마지막 날에 올라야 할 높이
    A -= B;               // 하루에 실제 상승하는 높이
    V % A == 0 ? printf("%d", 1 + V / A)
               : printf("%d", 2 + V / A);
}
  • V에서 A를 차감하여 마지막 날 오르는 높이를 미리 계산합니다.
  • 남은 높이를 하루에 오를 수 있는 높이 A‑B로 나눈 몫에 1을 더하면 전체 일수가 됩니다.
  • 나머지가 존재하면 하루가 더 필요하므로 +1을 추가합니다.
Back to Blog

Related posts

Read more »

1390. Four Divisors

Problem Statement Given an integer array nums, return the sum of divisors of the integers in that array that have exactly four divisors. If there is no such in...