1 ~ N 의 숫자를 차례대로 for loop을 돌린다.
약수의 개수가 홀수면 문이 열려있다.
그런데 약수의 개수가 홀수라면 완전제곱수이다.
그래서 1 ~ N까지의 완전제곱수 개수를 구하면 된다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
/** | |
* https://www.acmicpc.net/problem/6359 | |
* BOJ 백준온라인져지 6359 만취한 상범 풀이 | |
*/ | |
int main(){ | |
int *openList = new int[101]; | |
int testCase; | |
scanf("%d", &testCase); | |
while(testCase--){ | |
int numberOfRoom; | |
scanf("%d", &numberOfRoom); | |
if(!openList[numberOfRoom]) | |
for(int i = 1; i * i <= numberOfRoom; i++) | |
openList[numberOfRoom]++; | |
printf("%d\n", openList[numberOfRoom]); | |
} | |
} |
'IT > 알고리즘' 카테고리의 다른 글
BOJ 백준온라인져지 13410 거꾸로 구구단 풀이 (0) | 2017.12.11 |
---|---|
BOJ 백준온라인져지 2711 오타맨 고창영 풀이 (0) | 2017.12.11 |
BOJ 백준온라인져지 6378 디지털 루트 풀이 (0) | 2017.12.11 |
BOJ 백준온라인져지 6376 e 계산 풀이 (0) | 2017.12.11 |
BOJ 백준온라인져지 2217 로프 풀이 (0) | 2017.12.10 |