题目描述
Two positive integers $a$ and $b$ are 2-friendly when $gcd(a,b)=2^t,t>0$. For example, $24$ and $40$ are 2-friendly because $gcd(24,40)=8=2^3$ while $24$ and $36$ are not because $gcd(24,36)=12=2^2\cdot 3$ not a power of $2$.
Let $f(n)$ be the number of pairs, $(p,q)$, of positive integers with $1\leq p<q\leq n$ such that $p$ and $q$ are 2-friendly. You are given $f(10^2)=1031$ and $f(10^6)=321418433$ modulo $1000000007$ .
Find $f(10^{11})$ modulo $1000000007$.
题意
问你所有满足$1\leq p<q\leq 1e11$,并且$gcd(p,q)==2^t$的对数
分析
显然可以对于每个$2^t$单独考虑,不妨设$2^t = x$,可以得到
$$
ans = \sum_{i=1}^{upper/x} \varphi(i)
$$
然后显然是各种筛法搞一下,我这里用的杜教筛,然后稍微推一推就可以得到
$$
s(m) = \frac{m\ast (m+1)}{2} - \sum_{d=2}^{m} s(\lfloor \frac{m}{d} \rfloor)
$$
然后分块一下,递归搞下去就行了$\dots$
代码
给大佬递上我奇丑无比的代码 (/ω\)
1 |
|