当前位置:网站首页>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限制,需要分奇偶讨论一下。
数的位数很大,需要用字符串,这样的话,闭区间,左边的数减一不好计算,需要特判一下。
代码:
边栏推荐
- LeetCode 138. Copy a linked list with random pointers
- Excel函数公式大全—HLOOKUP函数
- If someone asks you about distributed transactions again, throw this to him
- LeetCode 92. Reverse Linked List II
- Cannot find symbol log because lombok is not found
- 不止跑路,拯救误操作rm -rf /*的小伙儿
- APP automation testing practice based on UiAutomator2+PageObject mode
- Introduction to Software Architecture
- WeChat applet, global variables change in one place and the state in other places also changes.
- LeetCode 25. K 个一组翻转链表
猜你喜欢

Since the media hot style title how to write?Taught you how to write the title

mpf6_Time Series Data_quandl_correct kernel PCA_AIC_BIC_trend_log_return_seasonal_decompose_sARIMAx_ADFull

英特尔推送20220809 CPU微码更新 修补Intel-SA-00657安全漏洞

Intel pushes 20220809 CPU microcode update to patch Intel-SA-00657 security vulnerability

A little self-deprecating deconstruction about farmers "code"

Where can I view the version record of WeChat applet submission review history?

网络套接字(UDP和TCP编程)

2016,还是到了最后

Go 事,Gopher 要学的数字类型,变量,常量,运算符 ,第2篇

Can CLIP also do segmentation tasks?The University of Göttingen proposed a model CLIPSeg that uses text and image prompts to perform three segmentation tasks at the same time, draining CLIP capabiliti
随机推荐
LeetCode50天刷题计划(Day 19—— 在排序数组中查找元素的第一个和最后一个位置(9.10-10.40)
石墨文档打开文档时快速定位到上次写的位置
jlink and swd interface definition
LeetCode 25. A set of K flipped linked lists
正则表达式常用示例
迈矽科推出高性能77GHz毫米波雷达芯片,尚未量产就已获数万颗订单
Centos7 environment uses Mysql offline installation package to install Mysql5.7
【Redis】内存回收策略
Ssm framework construction process [easy to understand]
7. Instant-ngp
LeetCode 25. K 个一组翻转链表
制品库是什么?
2016,还是到了最后
HDU 4372:Count the Buildings (Stirling数)
Samsung plans to start producing semiconductor components in Vietnam in 2023
The 6th "Blue Hat Cup" National College Student Network Security Skills Competition Semi-Final Part WriteUp
苹果逆势扩大iPhone 14系列备货,总量或达9500万部
Redis常用命令
VSCode远程连接服务器报错:Could not establish connection to “xxxxxx”的可能错误原因及解决
Servlet---解决post请求中中文乱码问题