Bubble Cup13-J. Bubble Cup hypothesis-数学、进位制

link:https://codeforces.com/contest/1423/problem/J
Given a number \(m\), how many polynomials \(P\) with coefficients in set \({\{0,1,2,3,4,5,6,7\}}\) have: \(P(2)=m\)?

\(1\leq m\leq 10^{18}\).


对系数在0~7内应该要很敏感,想到8进制,假设多项式 \(P=\sum_i a_i x^i\), $$P(2)=a_0+2a_1+4a_2+8a_3+16_4+32a_5+\dots=(a_0+8a_3+\dots)+2(a_1+8a_4+\dots)+4(a_2+8a_5+\dots)=m$$
问题转换成, \(m=a+2b+4c\) 有多少组非负整数解,这是容易的:

\[\begin{aligned} ans&=\sum_{c}\sum_{b} [m-4c-2b\geq 0]=\sum_c \lfloor \frac{m-4c}{2}+1\rfloor=\sum_{c=0}^{\lfloor m/4\rfloor}(\lfloor\frac{m}{2}+1\rfloor-2c)\\&=\lfloor\frac{m}{2}+1\rfloor \cdot\lfloor\frac{m}{4}+1\rfloor-\lfloor\frac{m}{4}+1\rfloor\cdot \lfloor\frac{m}{4}\rfloor\\ &=\lfloor\frac{m}{4}+1\rfloor\cdot(1+\lfloor\frac{m}{2}\rfloor-\lfloor\frac{m}{4}\rfloor) \end{aligned}\]

极简代码,但是这题居然评分2400

// LUOGU_RID: 158543323
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
int main(){
    fastio;
    int tc;cin>>tc;
    while(tc--){
        ll m;cin>>m;
        cout<<(ll)(m/4+1)%MOD*((m/2+1-(m/4))%MOD)%MOD<<endl;
    }
    return 0;
}
posted @ 2024-05-11 00:43  yoshinow2001  阅读(6)  评论(0编辑  收藏  举报