알고리즘

[알고리즘] 백준 8320 - 직사각형을 만드는 방법 (C++)

blueberrysoda 2024. 10. 31. 23:56

[문제 링크] : https://www.acmicpc.net/problem/8320

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int N, Ans;

int solve(int n){
    int div = 2, res = 1;
    
    if(n == 1 || n == 2){
        return 1;
    }
    while(n != 1){
        int cnt = 0;
        while(n % div == 0){
            n /= div;
            cnt++;
        }
        div++;
        res *= (cnt + 1);
    }
    return (res + 1) / 2;
}

int main(){
    cin >> N;
    for(int i=1; i<=N; i++){
        Ans += solve(i);
    }
    cout << Ans << "\n";
    return 0;
}