반응형
    
    
    
  
                              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
                            
                        
                          
                          - HTTP
- 쉬운 문제
- javascript
- 수학
- Algorithm
- Node.js
- 타입스크립트
- 프로그래머스
- HTTP 완벽 가이드
- Nestjs
- TCP
- 백준
- 가천대
- 알고리즘
- Crawling
- 그래프
- dp
- socket
- dfs
- 레벨 1
- BFS
- ip
- 크롤링
- 프로그래머스 레벨 2
- type challenge
- typescript
- 타입 챌린지
- 소켓
- 문자열
- 자바스크립트
                            Archives
                            
                        
                          
                          - Today
- Total
kakasoo
[node.js] 곱셈 ( 백준 1629번 ) 본문
반응형
    
    
    
  const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
rl.on("line", (line) => {
    let [a, b, c] = line.split(" ").map(BigInt);
    const pow = (a, b, c) => {
        if (b == 0) {
            return BigInt(1);
        }
        const temp = pow(a, BigInt(parseInt(b / BigInt(2))), c);
        if (b % BigInt(2)) {
            return (((temp * temp) % c) * a) % c;
        } else {
            return (temp * temp) % c;
        }
    };
    console.log(Number(pow(a, b, c)));
});
상당히 시간이 오래 걸린 문제이다. 재귀를 사용하지 않고 풀고 있었다. while문을 써서.
그런데 그게 더 어려웠던 것 같다. 문제를 풀기 전에 생각하는 습관을 들여야 하는데 그러질 못했던 점을 반성한다.
꼭 반성만 한다 (...)
반응형
    
    
    
  '프로그래밍 > 알고리즘 풀이' 카테고리의 다른 글
| [node.js] 날짜 계산 ( 백준 1476번 ) (0) | 2021.05.12 | 
|---|---|
| [node.js] 일곱 난쟁이 ( 백준 2309번 ) (0) | 2021.05.12 | 
| [node.js] 요세푸스 문제 ( 백준 1158번 ) (0) | 2021.04.16 | 
| [node.js] 트리의 부모 찾기 ( 백준 11725번 ) (0) | 2021.04.15 | 
| [node.js] 문자열 분석 ( 백준 10820번 ) (0) | 2021.04.15 | 
 
                   
                   
                  