QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#44038#4543. SumireCfer#RE 0ms0kbC++171.4kb2022-08-12 13:48:172022-08-12 13:48:18

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-12 13:48:18]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2022-08-12 13:48:17]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<cmath>
#include<bitset>
#include<cmath>

#define int long long 
#define x first
#define y second
#define ps push_back
#define endl '\n'

#define kd ios::sync_with_stdio(false);cin.tie();cout.tie(0);
using namespace std;
typedef pair<int,int>pi;
const int N=15,mod=1e9+7;
int lowbit(int x){return x&-x;}
int gcd(int a,int b){return a%b==0?b:gcd(b,a%b);}

int a[N];
int d[N][N];
int k,B,D;

int qmi(int x,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=res*x%mod;
		x=x*x%mod;
		b>>=1;
	}
	return res;
	
}
int dfs(int len,int sum,int lead,int limit)
{
	if(!len)
	{
		if(lead&&!D)return 1;
		return qmi(sum,k)%mod;	
	}
	if(!lead&&!limit&&d[len][sum]!=-1)return d[len][sum]%mod;
	
	int up=limit?a[len]:B-1;
	int res=0;

	for(int i=0;i<=up;i++)
	{
		int t=sum;
		if(i==D)
		{
			if(!D)
			{
				t=sum+(lead==0);
			}
			else t=sum+1;
		}
		else t=sum;
		res=(res+dfs(len-1,t,lead&&i==0,limit&&i==up))%mod;
	}
	
	return limit?res:(lead?res:d[len][D]=res);
	
}

int get(int x)
{
	memset(d,-1,sizeof d);
	int len=0;
	while(x)a[++len]=x%B,x/=B;	
	return dfs(len,0,1,1);
}

void solve()
{
	int l,r;
	cin>>k>>B>>D>>l>>r;
	cout<<((get(r)-get(l-1))%mod+mod)%mod<<endl;
}

signed main()
{
	kd;
	int _;_=1;
	cin>>_;
	while(_--)solve();	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

10000
3 207891369 69789899 964252340141144201 993463302889356041
3 747663427 196567324 607861784354966835 737019014793415965
7 4 1 75021281026163040 281275352760223247
159801714 6 4 57793681483331990 719907284728404544
760336565 3 2 640278753805042190 790056554571568287
3 3 0 370833904610234656 7289...

output:


result: