結果

問題 No.589 Counting Even
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-11-03 22:41:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,004 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 168,100 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 05:11:10
合計ジャッジ時間 2,169 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
#define FAC_MAX 200001
typedef long long ll;
ll fac_memo[FAC_MAX];
int fac_memo_max = 0;

ll fac(ll a)
{
    if (a <= fac_memo_max) return fac_memo[a];

    fac_memo[0] = 1;
    rep(i, fac_memo_max + 1, a + 1)
    {
        fac_memo[i] = fac_memo[i - 1] * i;
    }

    fac_memo_max = a;

    return fac_memo[a];
}
ll aCb(ll a, ll b)
{
    if (a == 0) return 1;
    if (a < b) return 0;
    return fac(a) / (fac(a - b) * fac(b));
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/



ll N;
//---------------------------------------------------------------------------------------------------
ll f(ll a) {
    if (a == 0 or a == 1) return 0;

    if (a % 2 == 0) return f(a / 2) + a / 2;
    return 2 * f(a / 2);
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    cout << f(N) << endl;
    return;

    rep(n, 0, 20) {
        printf("<%d>\n", n);
        int cnt = 0;
        rep(i, 0, n + 1) {
            ll x = aCb(n, i);
            if (x % 2 == 0) cnt++;
            printf(" %lld", x);
        }
        printf(" [%d] \n", cnt);
    }
}
0