当前位置:网站首页>CodeForces - 628D (digital dp)
CodeForces - 628D (digital dp)
2022-08-10 12:16: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
题目大意:
Find the number of a certain number in an interval,需要是m的倍数,And odd digits cannot be includedd,Even numbers are requiredd.The number of digits is2000位.
思路:
首先是数位dp.
关于m的限制,Just calculate the edge modulo directly.d限制,Need to discuss parity.
The number of digits is large,Strings are required,这样的话,闭区间,The number on the left minus one is not easy to calculate,需要特判一下.
代码:
边栏推荐
- 你有一份斗破苍穹词库,请查收
- 时间序列的数据分析(五):简单预测法
- LeetCode 362. Design Hit Counter
- Stroke Practice - 62 Valid Sudokus
- Samsung plans to start producing semiconductor components in Vietnam in 2023
- SMIC CIM localization project suspended?Rising software: not shut down, changed to remote development!
- LeetCode 92. 反转链表 II
- 搜索--09
- LeetCode 146. LRU 缓存
- gpu-admission 源码分析
猜你喜欢
你是怎么知道数据库 Htap 能力强弱的?怎么能看出来
Flutter气泡框实现
dedecms supports one-click import of Word content
mpf6_Time Series Data_quandl_correct kernel PCA_AIC_BIC_trend_log_return_seasonal_decompose_sARIMAx_ADFull
Module 9 - Designing an e-commerce seckill system
22年BATJ大厂必问面试题(复盘):JVM+微服务+多线程+锁+高并发
7. Instant-ngp
一文详解 implementation api embed
项目部署、
再有人问你分布式事务,把这篇扔给他
随机推荐
个推数据资产管理经验 | 教你打造数据质量心电图,智能检测数据“心跳”异常
LeetCode 362. Design Hit Counter
You have a Doubaqiong thesaurus, please check it
Licking Exercise - 60 Maximum key-value sum of binary search subtrees
网络套接字(UDP和TCP编程)
用低代码驱动IT现代化
Ssm framework construction process [easy to understand]
LeetCode 82. 删除排序链表中的重复元素 II
Analysis of the implementation principle of UUID from the perspective of source code
Dining (web stream)
你有一份斗破苍穹词库,请查收
中芯CIM国产化项目暂停?上扬软件:未停摆,改为远程开发!
迈矽科推出高性能77GHz毫米波雷达芯片,尚未量产就已获数万颗订单
mpf6_Time Series Data_quandl_correct kernel PCA_AIC_BIC_trend_log_return_seasonal_decompose_sARIMAx_ADFull
StoneDB Document Bug Hunting Season 1
What are some useful performance testing tools recommended? Performance testing report charging standards
The god-level Alibaba "high concurrency" tutorial - basic + actual combat + source code + interview + architecture is all-inclusive
LeetCode 109. 有序链表转换二叉搜索树
Configuration swagger
7. Instant-ngp