File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // a^b
2+ // https://www.acmicpc.net/problem/10827
3+
4+ const fs = require ( 'fs' ) ;
5+ const stdin = ( process . platform === 'linux'
6+ ? fs . readFileSync ( '/dev/stdin' ) . toString ( ) . trim ( )
7+ : `0.1 1`
8+ ) . split ( '\n' ) ;
9+
10+ const input = ( ( ) => {
11+ let line = 0 ;
12+ return ( ) => stdin [ line ++ ] ;
13+ } ) ( ) ;
14+
15+ const [ a , b ] = input ( )
16+ . split ( ' ' )
17+ . map ( ( each ) => Number ( each ) ) ;
18+
19+ const aArr = a . toString ( ) . split ( '' ) ;
20+ const indexOfDot = aArr . indexOf ( '.' ) ;
21+
22+ const dotPosition = (
23+ BigInt ( 10 ** aArr . slice ( indexOfDot + 1 , aArr . length ) . length ) ** BigInt ( b )
24+ ) . toString ( ) ;
25+
26+ const converToInt =
27+ aArr . slice ( 0 , indexOfDot ) . join ( '' ) +
28+ aArr . slice ( indexOfDot + 1 , aArr . length ) . join ( '' ) ;
29+
30+ const calc = ( BigInt ( converToInt ) ** BigInt ( b ) ) . toString ( ) ;
31+
32+ const index = calc . length - dotPosition . length + 1 ;
33+
34+ if ( index >= 0 ) {
35+ return console . log (
36+ calc . slice ( 0 , index ) + '.' + calc . slice ( index , calc . length )
37+ ) ;
38+ }
39+
40+ return console . log ( '0.' + '0' . repeat ( - index ) + calc ) ;
41+
42+ /*
43+
44+ ## How
45+ ์กฐํฉ์ BigInt๋ฅผ ์จ์ผ ํ๋ ๋ฌธ์ ๋ฅผ ์ ํ๊ณ BigInt ๊ด๋ จ ๋ฌธ์ ๋ฅผ ํ ๋ฒ ๋ ํ์ด๋ณด๊ณ ์ถ์ด์ ์ ์ ํ๋ค.
46+
47+ ์์์ ๊ฑฐ๋ญ์ ๊ณฑ์ ๊ตฌํ๋ ๋ฌธ์ ์ธ๋ฐ ๊ทธ๋๋ก ์ฐ์ ํค ๋ฒ๋ฆฌ๋ฉด ์ค์ฐจ๊ฐ ์๊ธฐ๊ฒ ๋๋ค. ๋ฐ๋ผ์ `.`์ ์์น๋ฅผ ๊ธฐ์ตํ๊ณ . ์ ์์ ๋ฒ๋ฆฐ ๋ค ์ ์ํํ ์๋ฅผ BigInt๋ก ์ฐ์ฐํด์. ์ด ์์ด์ผ ํ ์์น์ ์ถ๊ฐํ๋๋ก ํ๋ฉด ๋๋ค.
48+
49+ `.`์ ์์น๋ ์ด๋ ๊ฒ ๊ณ์ฐํ ์ ์๋ค. ๋จผ์ "10 ^ (`.` ์ดํ์ ์ซ์ ๊ฐ์)"์ "b ๋งํผ ๊ฑฐ๋ญ์ ๊ณฑํ ์์ ๊ธธ์ด"๋ฅผ ๊ตฌํ๋ค. ์ ์ฒด ์ฐ์ฐ ๊ฒฐ๊ณผ ๊ธธ์ด์์ ํด๋น ๊ธธ์ด๋ฅผ ๋บ ๋ค + 1 ํ๋ฉด ์ฐ์ฐ ํ `.`์ด ์์ด์ผ ํ ์์น๋ฅผ ๊ตฌํ ์ ์๋ค.
50+
51+ ์ด๋ ๊ฒ ์ ์ ์์น๋ฅผ ๊ตฌํ๋ฉด ์์์ธ ๊ฒฝ์ฐ๊ฐ ์๊ธฐ๋๋ฐ "0. + (0 * ๊ธธ์ด) + ๊ณ์ฐํ ์" ๋ก ์ฒ๋ฆฌํ๋ฉด ๋๋ค.
52+
53+ ## Retrospective
54+
55+ */
You canโt perform that action at this time.
0 commit comments