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 | 29 | 30 |
Tags
- express
- Google Developer API
- java
- --watch
- spread 연산자
- css framework
- server
- linux
- Google Refund
- draganddrop
- Spring Boot
- react
- Unity Editor
- Camera Movement
- unity
- Digital Ocean
- MySQL
- docker
- critical rendering path
- Unity IAP
- Git
- mongoDB
- springboot
- Camera Zoom
- Packet Network
- OverTheWire
- screencapture
- rpg server
- SDK upgrade
- nodejs
Archives
- Today
- Total
우당탕탕 개발일지
[프로그래머스] Level 2. 숫자 블록 본문
https://school.programmers.co.kr/learn/courses/30/lessons/12923
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
1. 각 블록에는 자신의 약수 중 가장 큰수를 저장한다.
2. 수는 10,000,000보다는 작아야한다.
약수를 검사하는 횟수를 최대한 줄이기 위해서 , 숫자의 제곱근에서 시작한다. 약수 i를 찾고, i와 짝이되는 slot/i 두 숫자를 검사한다.
만약 slot/i 가 MAX보다 작다면 그 수가 가장 큰 약수이다.
아니라면 다음 약수 짝을 검사한다.
#include <string>
#include <vector>
#include <cmath>
using namespace std;
vector<int> solution(long long begin, long long end) {
vector<int> answer(end-begin+1, 0);
long long MAX = 10000000;
for(int slot = begin; slot<=end; slot++){
if(slot ==1)continue;
int value = 1;
for(int i=2; i<= sqrt(slot); i++){
if(slot%i!=0) continue;
if(slot/i<=MAX){
value = slot/i; //최대약수찾았음.
break;
}
value= i; //작은거라도 우선 넣음.
}
answer[slot-begin] = value;
}
return answer;
}
'Algorithm(c++) > Level 2' 카테고리의 다른 글
[프로그래머스] Level 2. 지게차와 크레인 (0) | 2025.03.22 |
---|---|
[프로그래머스] Level 2. 혼자 놀기의 달인 (1) | 2025.03.21 |
[프로그래머스] Level 2 . 이모티콘 할인행사 (0) | 2025.03.18 |
[프로그래머스] Level 2. 후보키 (1) | 2025.03.15 |
[프로그래머스] Level 2. 거리두기 확인하기 (0) | 2025.03.07 |