题目描述
Define $g(n,m)$ to be the largest integer k such that $2^k$ divides $(_m^n)$. For example, $(_5^{12})=792=2^3⋅3^2⋅11$, hence $g(12,5)=3$. Then define $F(n)=max{g(n,m):0\leq m\leq n}$. $F(10)=3$ and $F(100)=6$.
Let $S(N) = \sum_{n=1}^N F(n)$. You are given that $S(100)=389$ and $S(107)=203222840$.
Find $S(10^{16})$.
题意
定义 $g(n,m)$ 表示组合数 $C_n^m$ 唯一分解后,素因子 $2$ 的指数。
定义 $F(n)$ 为 $max{g(n,m):0\leq m\leq n}$
定义 $S(n)$ 为 $\sum_{n=1}^N F(n)$
求 $S(10^{16})$
分析
打个表可以很容易得到 $F(n)$ 对应的 $m$ 的关系为:$n+1-upperbit(n+1) = m$
其中 $upperbit(x)$ 表示 $x$ 二进制下的最高位。
然后就是分块随便搞一搞就行了。
代码
给大佬递上我奇丑无比的代码 (/ω\)
1 |
|
1 | package main |