题目描述

A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string "13" and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your task is to calculate how many wqb-numbers from 1 to n for a given integer n.

输入

Process till EOF. In each line, there is one positive integer n(1 <= n <= 1000000000).

输出

Print each answer in a single line.

样例输入

13
100
200
1000

样例输出

1
1
2
2 求小于n是13的倍数且含有“13”的数的个数,有多组数据,输入到结束。 dp[i][j][k][l]。i表示i位数j表示第i位是j的k表示是否包含13(k==0 or 1)L表示膜13是l的数的个数
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int dp[][][][];
int e[];
void init()
{
e[]=;
for(int i=;i<=;i++)e[i]=(e[i-]*)%;
dp[][][][]=;
for(int i=;i<=;i++)
for(int j1=;j1<=;j1++)
for(int j2=;j2<=;j2++)
for(int l=;l<;l++)
{
int yu=(l-(j1*e[i-])%+)%;//yu表示dp[][][][l]从dp[][][][yu]转移//yu+j1贡献的余数=l
dp[i][j1][][l]+=dp[i-][j2][][yu];
if(j1==&&j2==)dp[i][j1][][l]+=dp[i-][j2][][yu];
else dp[i][j1][][l]+=dp[i-][j2][][yu];
}
}
int solve(int a)
{
int len=,ans=,mod=,d[];bool t=;
while(a)
{
d[++len]=a%;a/=;
}
d[len+]=;
for(;len>=;len--)
{
for(int i=;i<d[len];i++)
{
int yu=(-(mod*e[len])%)%;//算上高位mod13的余数还要加多少(yu)mod13才会得0
ans+=dp[len][i][][yu];
if(t||d[len+]==&&i==)ans+=dp[len][i][][yu];
}
if(d[len+]==&&d[len]==)t=;
mod=(mod*+d[len])%;
}
return ans;
}
int main()
{
int n;init();
while(scanf("%d",&n)!=EOF)
{
printf("%d\n",solve(n+));
}
return ;
}
 

[HDU_3652]B-number的更多相关文章

  1. JavaScript Math和Number对象

    目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...

  2. Harmonic Number(调和级数+欧拉常数)

    题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式, ...

  3. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  4. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

  5. 移除HTML5 input在type="number"时的上下小箭头

    /*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...

  6. iOS---The maximum number of apps for free development profiles has been reached.

    真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...

  7. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  8. [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  9. [LeetCode] Number of Boomerangs 回旋镖的数量

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  10. [LeetCode] Number of Segments in a String 字符串中的分段数量

    Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...

随机推荐

  1. E - Nature Reserve CodeForces - 1059D

    传送门 There is a forest that we model as a plane and live nn rare animals. Animal number iihas its lai ...

  2. Android 自定义WebView 实现可以加载缓存数据

    1.自定义WebView说明 1.1.这个WebView可以加载缓存的数据.(需要后端配合,将html转换成一个字符串,主要是图片要用特殊格式) 1.2.注入了图片链接,为了方便点击webView中的 ...

  3. Enhacing the content with JavaScript

    What not to do :  In theory , you could use JavaScript to add important content to a web page. Howev ...

  4. P3817 小A的糖果(洛谷月赛)

    P3817 小A的糖果 题目描述 小A有N个糖果盒,第i个盒中有a[i]颗糖果. 小A每次可以从其中一盒糖果中吃掉一颗,他想知道,要让任意两个相邻的盒子中加起来都只有x颗或以下的糖果,至少得吃掉几颗糖 ...

  5. oracle(sql)基础篇系列(三)——数据维护语句、数据定义语句、伪列

    DML语句 insert 向表中插入新的记录 --三种插入方式 --(1)不写字段的名字,直接按照字段的顺序把值逐个往里插 insert into dept2 values(50,'DANAME',' ...

  6. Maven学习 (五) Elipse中发布一个Maven项目到Tomcat

    对于maven初学者的我,经常遇到一个问题就是,maven项目创建成功后,本来已经添加了jar的依赖,但是发布到Tomcat中就是没有jar包存在, 启动Tomcat总是报没有找到jar包,可项目结构 ...

  7. vlc 编译

    一.有用的网址: https://forum.videolan.org/search.php 二.只编译Java apk部分: source env.shmake distcleanmake -e 编 ...

  8. 用scrapy数据抓取实践

    本文来自网易云社区 作者:沈高峰 数据分析中需要用到的不少数据都是需要进行抓取的,并且需要对抓取的数据进行解析之后存入数据库.scrapy是一个强大的爬虫框架,本文简单介绍下使用scrapy进行垂直抓 ...

  9. PJMEID学习之视频的捕捉与播放

    pjmedia是pjsip的视频部分,官网明确提示,要想使用pjmedia离不开directshow/sdl/ffmpeg这三个库. 软件版本的限制: ffmpeg不能高于1.25.(建议下载1.01 ...

  10. ARC下,不显式指定任何属性关键字时,默认的关键字都有哪些

    1.对应基本数据类型默认关键字是 atomic,readwrite,assign 2.对于普通的 Objective-C 对象 atomic,readwrite,strong