当前位置:网站首页>CodeForces - 628D (数位dp)
CodeForces - 628D (数位dp)
2022-08-10 11:32:00 【51CTO】
Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else.
For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic, 34 is 4-magicand 71 is 1-magic.
Find the number of d-magic numbers in the segment [a, b] that are multiple of m. Because the answer can be very huge you should only find its value modulo 109 + 7 (so you should find the remainder after dividing by 109 + 7).
Input
The first line contains two integers m, d (1 ≤ m ≤ 2000, 0 ≤ d ≤ 9) — the parameters from the problem statement.
The second line contains positive integer a in decimal presentation (without leading zeroes).
The third line contains positive integer b in decimal presentation (without leading zeroes).
It is guaranteed that a ≤ b, the number of digits in a and b are the same and don't exceed 2000.
Output
Print the only integer a — the remainder after dividing by 109 + 7 of the number of d-magic numbers in segment [a, b] that are multiple of m.
Examples
Input
2 6 10 99
Output
8
Input
2 0 1 9
Output
4
Input
19 7 1000 9999
Output
6
题目大意:
求一个区间内某种数的个数,需要是m的倍数,并且奇数位不能包含d,偶数为必须包含d。数的位数是2000位。
思路:
首先是数位dp。
关于m的限制,直接便计算边取模就行。d限制,需要分奇偶讨论一下。
数的位数很大,需要用字符串,这样的话,闭区间,左边的数减一不好计算,需要特判一下。
代码:
边栏推荐
- Redis常用命令
- Intel pushes 20220809 CPU microcode update to patch Intel-SA-00657 security vulnerability
- 石墨文档打开文档时快速定位到上次写的位置
- Apple bucks the trend and expands iPhone 14 series stocking, with a total of 95 million units
- Samsung plans to start producing semiconductor components in Vietnam in 2023
- [E-commerce operation] Do you really understand social media marketing (SMM)?
- 力扣练习——59 从二叉搜索树到更大和树
- 英特尔推送20220809 CPU微码更新 修补Intel-SA-00657安全漏洞
- What are some useful performance testing tools recommended? Performance testing report charging standards
- jlink 与 swd 接口定义
猜你喜欢

Article take you understand interrupt the key driver of polling mechanism
Database management tool: dynamic read-write separation

你有一份斗破苍穹词库,请查收

How to join We Media, learn about these 5 monetization modes, and make your account quickly monetize

VSCode远程连接服务器报错:Could not establish connection to “xxxxxx”的可能错误原因及解决

A case of violent parameter tuning in machine learning

单目操作符(含原码反码补码转换)

Module 9 - Designing an e-commerce seckill system

The 6th "Blue Hat Cup" National College Student Network Security Skills Competition Semi-Final Part WriteUp

制品库是什么?
随机推荐
力扣练习——59 从二叉搜索树到更大和树
自媒体爆款标题怎么写?手把手教你写热门标题
力扣练习——56 寻找右区间
LeetCode 138. 复制带随机指针的链表
codevs 2370 Small room tree (LCA)
LeetCode 237. 删除链表中的节点
10 个 Reduce 常用“奇技淫巧”
再有人问你分布式事务,把这篇扔给他
开源的作者,也有个生活问题
制品库是什么?
7、Instant-ngp
Licking Exercise - 59 From Binary Search Trees to Greater Sum Trees
力扣练习—— 矩形区域不超过 K 的最大数值和(hard)
石墨文档打开文档时快速定位到上次写的位置
你有一份斗破苍穹词库,请查收
【LeetCode】640. 求解方程
Configuration swagger
厚积薄发!安全狗再次获得科技成果转化认证!
一文详解 implementation api embed
It is rumored that Samsung 3nm has won the second customer, and the current production capacity is in short supply