結果
| 問題 | 
                            No.642 Two Operations No.1
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2018-02-02 22:15:16 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 390 bytes | 
| コンパイル時間 | 661 ms | 
| コンパイル使用メモリ | 70,572 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-12-31 07:42:03 | 
| 合計ジャッジ時間 | 1,268 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 WA * 11 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int bitcnt(long long n) {
  int res = 0;
  while (n > 0) {
    res++;
    n &= n - 1;
  }
  return res;
}
int main() {
  long long n;
  cin >> n;
  int ans = 1e9;
  for (int i = 0; i <= 18; i++) {
    if (1LL << i >= n) {
      ans = min(ans, i + bitcnt((1LL << i) - n));
    }
  }
  cout << ans << endl;
}