0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

「ある数でつくられた数列」を解くために:part2 (BigInt)

0
Posted at

今回は paiza の「「ある数でつくられた数列」を解くために:part2」の問題に挑戦!


問題概要

  • 入力として 3つの整数 A_1, A_2, A_3 が与えられる
  • それらを すべて掛け合わせた結果 を出力する問題
  • 入力は 1行・半角スペース区切り
  • 出力は 計算結果を1行で出力(余計な文字・空行は禁止)

※ 答えが最大で 10^10 程度の非常に大きな値になることがあるので、オーバーフローに注意!


入力例:

10000 10000 10000

出力例:

1000000000000




✅OK例:

const rl = require('readline').createInterface({ input: process.stdin });

const lines = [];
rl.on('line', line => lines.push(line));

rl.on('close', () => {
    const 「A1, A2, A3] = lines[0].split(' ').map(BigInt);
    
    const ans = A1 * A2 * A3;
    console.log(String(ans));
});




📝まとめ

  • 大きな整数の正確な計算には BigInt を使う
  • BigInt を使うときの注意点
    • BigInt(値) または 123n のように明示する
    • Number と BigInt は混ぜて計算できない
  • BigInt の結果は
    • console.log(String(ans)) のように 文字列にして出力
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?