1
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?

【AtCoder C++】B- ABC076 - Addtion and Multiplication

Last updated at Posted at 2024-03-05

学習記録用 -B-Addition and Multiplication

#include <bits/stdc++.h>
using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  int sum = 1;
  //A(1*2),B(1+K)を合計でN回繰り返す。その最初値
  //A,Bを比較(if)して、値が小さいほうを実行。その繰り返し
  for (int i = 0; i < N; i++){
    int A = sum * 2;
    int B = sum + K;
    
    if(A<=B){
      //sum += Aではなくて、sum = A。sum += Aだと、sum = sum + A(sum*2)でsumを2回使って格納しているから間違い。
      sum = A;
    }else{
      sum = B;
    }
  }
  cout << sum << endl;
  
}

最初sum += A / sum += Bにしていて、間違えていた!修正した!

1
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
1
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?