2020牛客寒假算法基础集训营5 F-碎碎念
思路:
数位dp + 前缀和
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <map>
#include <stack>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll maxn = 1e5 + 5;
ll f[maxn][2];
ll s[maxn];
int main(){
int x,Q,L,R;
cin>>x>>Q;
f[0][0]=1;
for(int i=1;i<=100000;i++){
f[i][0]=(f[i-1][0]+f[i-1][1])%mod;
if(i-x>=0) f[i][1]=f[i-x][0]%mod;
}
for(int i=1;i<=100000;i++){
s[i]=(s[i-1]+f[i][0]+f[i][1])%mod;
}
while(Q--){
cin>>L>>R;
ll res=(mod+s[R]-s[L-1])%mod;
cout<<res<<'\n';
}
return 0;
}