题目大意
解题思路
可以用杨辉三角求解组合数,再用前缀和求解答案。因为我比较蠢,所以我就分解质因数,但是实际上只要对k取模就可以了。
code
#include
#include
#include
#include
#define LD double
#define LL long long
#define max(x,y) ((x>y)?x:y)
#define min(x,y) ((x
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define fd(i,j,k) for(int i=j;i>=k;i--)
using namespace std;
int const maxn=2000;
int t,K,n,m,f[maxn+10][20],g[maxn+10][maxn+10],ss[9]={8,2,3,5,7,11,13,17,19},inf=1e9;
int main(){
freopen("problem.in","r",stdin);
freopen("problem.out","w",stdout);
scanf("%d%d",&t,&K);
int ii;
fo(i,1,maxn){
ii=i;
fo(j,1,8){
f[i][j]=f[i-1][j];
while(ii%ss[j]==0){
f[i][j]++;
ii/=ss[j];
}
}
}
int kk,cnt,tmp;
fo(i,1,maxn){
fo(j,1,i){
g[i][j]=g[i-1][j]+g[i][j-1]-g[i-1][j-1];
kk=K;tmp=inf;
fo(k,1,8){
cnt=0;
while(kk%ss[k]==0){
cnt++;
kk/=ss[k];
}
if(cnt)tmp=min(tmp,(f[i][k]-f[j][k]-f[i-j][k])/cnt);
}
if((tmp!=inf)&&(tmp>0))g[i][j]++;
}
fo(j,i+1,maxn)
g[i][j]=g[i-1][j]+g[i][j-1]-g[i-1][j-1];
}
int n,m;
fo(i,1,t){
scanf("%d%d",&n,&m);
printf("%d\n",g[n][m]);
}
return 0;
}