---
id: 493
lang: en
translation_of: index.md
source_sha256: 01b8425eea9c327fac313cc3cc468abcc054c1a6f8c9eac1326ada5f2cc6dd2c
title: "P3773: [CTSC2017] Gift — Solution"
description: "There is an “obvious” theorem: if n&k==k, then C(n,k) is odd."
tags: ["OI","Math","Binomial Coefficients"]
translated: 2026-11-27
translator: Claude Opus 5.5
translator_model: claude-opus-5-5
translation_notes:
  - "Problem name 吉夫特 is a phonetic transliteration of “gift”, rendered as “Gift”."
---

## A <span class="slang" data-zh="神仙" data-gloss="shénxiān, “immortal”. Someone, or a problem or idea, so brilliant it seems superhuman.">Godlike</span> Approach

There is an “obvious” theorem: if $n\&k==k$, then $C^k_n$ is odd. The specific <span class="slang" data-zh="感性证明" data-gloss="gǎnxìng zhèngmíng, “perceptual proof”. OI slang for a hand-wavy, intuitive argument instead of a rigorous proof.">hand-wavy proof</span>: [litble's proof](https://www.luogu.org/blog/litble-blog/solution-p3773). So, straight to the code.

## Code

```cpp
// P3773.cpp
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAX_N = 233393, mod = 1000000007;
int n, arr[MAX_N], bucket[MAX_N], f[MAX_N], ans;
int getMod(int num) { return num >= mod ? num - mod : num; }
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &arr[i]), bucket[arr[i]] = i;
    for (int i = n; i >= 1; i--)
    {
        f[i] = 1;
        for (int j = (arr[i] & (arr[i] - 1)); j; j = arr[i] & (j - 1))
            if (bucket[j] > i)
                f[i] = getMod(f[i] + f[bucket[j]]);
        ans = getMod(ans + f[i]);
    }
    ans = (ans - n + mod) % mod;
    printf("%d", ans);
    return 0;
}
```
