CF1423J Bubble Cup hypothesis

Luogu 链接
CodeForces 链接
Virtual Judge 链接

题意

题目描述

给定一正整数 \(y\),求有多少不同的多项式 \(P\),使得:

  • \(P(2)=y\)
  • 多项式 \(P\) 的任意一项的系数 \(a\) 都有:\(a\in\mathbb Z\),且 \(0\le a<8\)

由于答案可能很大,你只需输出其对 \(10^9+7\) 取模后的值。


输入格式

多测,第一行一个正整数 \(T\)\(T\le5\times10^5\)),代表组数。
每组数据第一行一个正整数 \(y\)\(1\le y\le10^{18}\)),含意见题目描述


输出格式

每组数据输出仅一行,代表你的答案。

思路

看到 \(8\),不妨往八进制上想一想。

首先设此多项式为:

\[a_0\times x^0+a_1\times x^1+a_2\times x^2+\cdots \]

\(x=2\),则有:

\[\begin{aligned} y&=a_0\times2^0+a_1\times2^1+a_2\times2^2+\cdots\\ &=(a_0\times8^0+a_3\times8^1+\cdots)+2\times(a_1\times8^0+a_4\times8^1+\cdots)+4\times(a_2\times8^0+a_5\times8^1+\cdots) \end{aligned}\]

因此,我们可以将括号内的三个八进制数设为 \(a\)\(b\)\(c\),问题就转化为求 \(a+2\times b+4\times c=y\) 的自然数解的组数。

考虑 \(a+2\times b=y'\) 时,此时显然 \(b\)\(0\)\(\lfloor\dfrac{y'}{2}\rfloor\) 的所有整数都符合条件,所以组数为 \(\lfloor\dfrac{y'}{2}\rfloor+1\)

\(y'=y-4\times c\),显然 \(c\) 可以取 \(0\)\(\lfloor\dfrac{y}{4}\rfloor\) 的所有整数,所以总的组数为:

\[\begin{aligned} \sum_{c=0}^{\lfloor\frac{y}{4}\rfloor}(\lfloor\dfrac{y-4\times c}{2}\rfloor+1)&=\sum_{c=0}^{\lfloor\frac{y}{4}\rfloor}(\lfloor\dfrac{y}{2}\rfloor -2\times c+1)\\ &=\lfloor\dfrac{y}{2}\rfloor\times(\lfloor\dfrac{y}{4}\rfloor+1)-\lfloor\dfrac{y}{4}\rfloor\times(\lfloor\dfrac{y}{4}\rfloor+1)+(\lfloor\dfrac{y}{4}\rfloor+1)\\ &=(\lfloor\dfrac{y}{2}\rfloor-\lfloor\dfrac{y}{4}\rfloor+1)\times(\lfloor\dfrac{y}{4}\rfloor+1) \end{aligned}\]

程序

AC 记录

#include<cstdlib>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdio>
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<iomanip>
#include<string>
#include<stack>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define ls rt<<1
#define rs rt<<1|1
#define lb(x) (x&-x)
#define pb push_back
using namespace std;
const ll mod=1e9+7;
//#define use_file
#define more_test
//#define need_init
#ifdef more_test
int T;
#endif

ll y;

void SOLVE(/*int test_id*/){
	scanf("%lld",&y);
	printf("%lld\n",((y>>2)+1)%mod*(((y>>1)-(y>>2)+1)%mod)%mod);
}
int main(){
	#ifdef use_file
	freopen("test.in","r",stdin);
	freopen("test.out","w",stdout);
	#endif
	#ifdef need_init
	init();
	#endif
	#ifdef more_test
	scanf("%d",&T);
	for(int i=1;i<=T;++i)SOLVE(/*i*/);
	#else
	SOLVE(/*1*/);
	#endif
	return 0;
}
posted @ 2025-03-24 20:17  LXcjh4998  阅读(15)  评论(0)    收藏  举报