codeforces 55D beautiful number [数学+数位DP]【动态规划+数论】

题目连接 : http://codeforces.com/problemset/problem/55/D ——————————-. D. Beautiful numbers time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard output V
摘要由CSDN通过智能技术生成

题目连接 : http://codeforces.com/problemset/problem/55/D
——————————-.
D. Beautiful numbers
time limit per test4 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful numbers in given ranges.

Input
The first line of the input contains the number of cases t (1 ≤ t ≤ 10). Each of the next t lines contains two natural numbers li and ri (1 ≤ li ≤ ri ≤ 9 ·10^18).

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).

Output
Output should contain t numbers — answers to the queries, one number per line — quantities of beautiful numbers in given intervals (from li to ri, inclusively).

Examples
input
1
1 9
output
9
input
1
12 15
output
2
———————————.

题目大意 :
就是求区间内能被所有位上的数字(!0)整除的数的个数

解题思路 :

困了 明天再写吧,,
首先这很明显是一个数位DP
满足被所有位上的数字(!0)整除的数 其实就是满足被这些位数的lcm整除
然后就是怎么处理一个数在不断变化中 还要对lcm{xi}取模呢
这时候就要仔细思索其中的奥妙 也是本题最重要的一点.
首先lcm{1~9}=2520;
想到每个数都是1~9中某些数字的lcm 所以他们一定能整除2520

因为 若a≡b(mod m) 且d|m 则a≡b(mod d);
转化一下设b已经是对m取完模的了
于是得到 若a % m=b%m 且d|m 则a % d = b%d;
因为 b=b%m 所以 b=b%m=b%d
所以 b%m%m=b%d%m
所以 b%m=b%d(km)%m

所以可以得到下

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值