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?

アルゴ式-素数の個数

  • 自然数Nの素数判定について1からNまでforで回したため素数判定時に割り切れた回数を2にして判定してしまった
    →2からN-1(その数自身で割らない)ようにすることで単純に割り切れたかどうかだけでflagを切り替えればよい

この解法に気づけなかった原因

  • 前回の1つの数を素数判定問題では平方根を取って素数判定をしていた。そのためその数自身で割るパターンの考慮が必要なかった。また、前回は何故か1ではなく2から割り始めていた

アルゴ式-回文の個数

  • reverse()を使うのがどう考えても早いが以下が模範解答
bool flag = true;
  int N = x.size();
  for (int i=0; i<N; ++i) {
    if (x[i] != x[(N-1)-i]) {
      flag = false;
    }
  }
  return flag;

前と後ろから同時に見ていって一致を確認

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?