ABC068 B - Break Number
問題はこちら
atcoder.jp
方針
特に難しい点はありませんが, のとき が出力されないよう変数maxを で初期化しています。
コード
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int count_max=0; int max=1; // 求める整数 for(int i=1; i<n+1; i++){ int count=0; int j=i; while(j%2==0){ j/=2; count++; } if(count>count_max){ count_max=count; max=i; } } cout<<max<<endl; }