#include<stdio.h>
#include<string.h>
using namespace std;
typedef long long ll; int a[];
int dp[][][]; //pos:当前位置
//mod:余数
//have :0:前一位不是1 1:前一位是1 2:有13
ll dfs(int pos,int mod,int have,bool limit){
if(pos==-) return mod == && have == ;
if(!limit && dp[pos][mod][have] != -)
return dp[pos][mod][have];//没有上限并且已被访问过
int up = limit?a[pos]:;
ll ans = ,i;
for(i = ;i <= up;i++){
int modx = (mod*+i)%;
int havex = have;
if(have == && i==) havex=;
if(have == && i!=) havex=;
if(have == && i == ) havex=;
ans += dfs(pos-, modx, havex, limit && i == a[pos]);
}
if(!limit) dp[pos][mod][have] = ans;
return ans;
} ll solve(ll x){
int pos=;
while(x){
a[pos++]=x%;
x/=;
}
return dfs(pos-,,,true);
}
int main(){
ll n;
memset(dp,-,sizeof(dp));
while(scanf("%lld",&n)!=EOF){
ll ans = solve(n);
printf("%lld\n",ans;
}
return ;
}

G - B-number的更多相关文章

  1. CF 724 G. Xor-matic Number of the Graph

    G. Xor-matic Number of the Graph 链接 题意: 给定一个无向图,一个interesting的三元环(u,v,s)满足,从u到v的路径上的异或和等于s,三元环的权值为s, ...

  2. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) G - Xor-matic Number of the Graph 线性基好题

    G - Xor-matic Number of the Graph 上一道题的加强版本,对于每个联通块需要按位算贡献. #include<bits/stdc++.h> #define LL ...

  3. G - Harmonic Number (II) 找规律--> 给定一个数n,求n除以1~n这n个数的和。n达到2^31 - 1;

    /** 题目:G - Harmonic Number (II) 链接:https://vjudge.net/contest/154246#problem/G 题意:给定一个数n,求n除以1~n这n个数 ...

  4. Codeforces 724 G Xor-matic Number of the Graph 线性基+DFS

    G. Xor-matic Number of the Graph http://codeforces.com/problemset/problem/724/G 题意:给你一张无向图.定义一个无序三元组 ...

  5. Codeforces G. Bus Number(dfs排列)

    题目描述: Bus Number time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  6. G - Harmonic Number (II) LightOJ - 1245

    算是一个找规律的题目吧. 枚举前sqrt(n)个数,数i出现的次数为n/i-n/(i+1),对答案的贡献为(n/i-n/(i+1))*i. 对于sqrt后边的数,可以直接由n/i获得,并且一定只出现一 ...

  7. LightOJ 1245 Harmonic Number (II)(找规律)

    http://lightoj.com/volume_showproblem.php?problem=1245 G - Harmonic Number (II) Time Limit:3000MS    ...

  8. 华中农业大学第五届程序设计大赛网络同步赛-G

    G. Sequence Number In Linear algebra, we have learned the definition of inversion number: Assuming A ...

  9. hzau 1205 Sequence Number(二分)

    G. Sequence Number In Linear algebra, we have learned the definition of inversion number: Assuming A ...

  10. input属性设置type="number"之后, 仍可输入e, E, -, + 的解决办法

    <el-input v-model="scope.row.variables.leaderbuweiscores.score" @keyup.native="cha ...

随机推荐

  1. 使用Windows API发送HTTP请求

    先看一个简单的GET示例 #include <Windows.h> #include <winhttp.h> #include <stdio.h> int main ...

  2. 分词系统简介:PHPAnalysis分词程序

    分词系统简介:PHPAnalysis分词程序使用居于unicode的词库,使用反向匹配模式分词,理论上兼容编码更广泛,并且对utf-8编码尤为方便. 由于PHPAnalysis是无组件的系统,因此速度 ...

  3. CSS动画硬件加速

    http://zencode.in/14.CSS%E5%8A%A8%E7%94%BB%E7%9A%84%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96.html http:// ...

  4. HDU3065 病毒侵袭持续中 —— AC自动机

    题目链接:https://vjudge.net/problem/HDU-3065 病毒侵袭持续中 Time Limit: 2000/1000 MS (Java/Others)    Memory Li ...

  5. Consul环境搭建

    大家在玩的时候 一定要使用ningx 1.9以上版本啊! 下载:wget https://releases.hashicorp.com/consul/0.7.5/consul_0.7.5_linux_ ...

  6. Discuz/X3.1去掉标题中的Powered by Discuz!以及解决首页标题后的"-"

    虽然不提倡大家去掉版权信息,但是在实际操作的时候还是去掉,毕竟每个页面标题最后面出现”Powered by Discuz!“会显得页面标题比较冗长. 经过本人的实践,论坛里也有操作方法,不过那个操作方 ...

  7. 《数学之美》第15章 矩阵计算和文本处理中两个分类问题——SVD分解的应用

    转载请注明原地址:http://www.cnblogs.com/connorzx/p/4170047.html 提出原因 基于余弦定理对文本和词汇的处理需要迭代的次数太多(具体见14章笔记),为了找到 ...

  8. poj图论解题报告索引

    最短路径: poj1125 - Stockbroker Grapevine(多源最短路径,floyd) poj1502 - MPI Maelstrom(单源最短路径,dijkstra,bellman- ...

  9. Linux-用户和权限

    1 Linux所有内容都是文件 归一的思想 面向对象的思想 文件只需要做增删改查的操作 2 延迟读取 一般的文本读取工具都是先将内容全部都读入内存中 cat的机制不同 是读一行显示一行 这与它的功能有 ...

  10. ROM的分类

    转载自:http://www.ic37.com/htm_tech/2012-5/82774_23811.htm ROM(只读存储器)按其内容写入方式,一般分为3种:固定内容ROM:可一次编程PROM: ...