본문 바로가기

Programming/BaekJoon

[C++] 백준 8320번 : 직사각형을 만드는 방법


https://www.acmicpc.net/problem/8320




#include <iostream>

#include <math.h>

using namespace std;


int main() {

int n;

cin >> n;

int *square = new int[n];


int cnt = 0;

for (int i = 0; i < n; i++) {

for (int j = 1; j <= sqrt(i+1); j++)

{

if ((i + 1) % j == 0)

cnt++;

}

square[i] = cnt;

cnt = 0;

}

int sum = 0;

for (int i = 0; i < n; i++)

sum += square[i];

cout << sum;

}