首页 技术 正文
技术 2022年11月21日
0 收藏 941 点赞 2,611 浏览 1531 个字

给出a,b,求出[a,b]中各位数字之和能整除原数的数的个数。1<=a<=b<=1e18.

注意到各位数字之和最大是153.考虑枚举这个东西。那么需要统计的是[0,a-1]和[0,b]内各位数字之和为x且能整除x的数字个数。

那么我们只需要数位dp一波即可。

令dp[pos][i][x]表示有pos位且数字之和为x的数mod P=i的数字个数。

则转移方程显然可得。

# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin...LL dp[][][], p[];
int wei[];LL dfs(int pos, int mod, int limit, int x, int P){
if (x<) return ;
if (pos==) return mod==&&x==;
if (!limit&&~dp[pos][mod][x]) return dp[pos][mod][x];
int up=limit?wei[pos]:;
LL res=;
FOR(i,,up) res+=dfs(pos-,(mod+P-(i*p[pos-]%P))%P,limit&&i==wei[pos],x-i,P);
if (!limit) dp[pos][mod][x]=res;
return res;
}
LL sol(LL x){
int pos=;
while (x) wei[++pos]=x%, x/=;
LL res=;
int top=min(,pos*);
FOR(i,,top) mem(dp,-), res+=dfs(pos,,,i,i);
return res;
}
int main ()
{
LL a, b;
p[]=; FO(i,,) p[i]=p[i-]*;
scanf("%lld%lld",&a,&b);
printf("%lld\n",sol(b)-sol(a-));
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,557
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898