結果

問題 No.1869 Doubling?
ユーザー Nzt3
提出日時 2022-09-25 01:48:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 469 bytes
コンパイル時間 1,805 ms
コンパイル使用メモリ 193,444 KB
最終ジャッジ日時 2025-02-07 14:39:42
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin>>N>>M;
  if(N<=30&&(1<<N-1)<=M){
    long long ans=0;
    for(int i=0;i<N;i++){
      ans+=1<<i;
    }
    cout<<ans<<'\n';
    return 0;
  }
  long long ans=0;
  int t=M;
  for(int i=0;i<N;i++){
    if(t==1){
      ans+=(N-i);
      break;
    }
    ans+=t;
    if(t%2){
      t=(t+2)/2;
    }else{
      t=t/2;
    }
  }
  cout<<ans<<'\n';
}
0