2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

競プロでc++のpowを使ったときの話

Last updated at Posted at 2020-11-29

#表示形式ミス

c++で実装されているpowは引数としてint, intをとったときdouble型で計算することになっており

int a = 1125;
cout << pow(a, 2) << endl;

としたときの出力は

1.26562e+06

となる。
しかし、一般にこの形式で答えを出力させることはないのでint型へキャストする必要がある。

int a = 1125;
cout << static_cast<int>(pow(a, 2)) << endl;

このときの出力は期待通り

1265625

となる。

2
3
2

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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?