Help us understand the problem. What is going on with this article?

ABC081B - Shift onlyを2で割れる回数の最小値から導く方法(Golang)

はじめに

ABC081B - Shift onlyを実際の操作のシミュレーションでのカウントではなく、
2で割れる回数の最小値から導く方法です。

package main

import (
  "fmt"
)

func main() {
  var n int
  min := 1000000000 // Aiの取りうる値の最大値
  fmt.Scanf("%d", &n)
  nums := make([]int, n)

  // n個の値を取得
  for i := 0; i < n; i++ {
    fmt.Scan(&nums[i])
  }

  for i :=0; i < n; i++ {
    lcnt := 0;
    // 2で割り切れる限り回し続ける
    for nums[i]%2 == 0 {
      nums[i] = nums[i]/2
      lcnt++ // 割った数をカウント
    }

    // 最小値より小さいカウントの場合入れ替え
    if min > lcnt {
      min = lcnt
    }
  }
  fmt.Println(min)
}

おわりに

説明文の操作の通り上から順序よく処理したくなりますが、選択肢として持っておきたいため書きました。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした