#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. 10.19-10.20 test

    2016 10.19-10.20 两天  题目by mzx Day1: T1:loverfinding 题解:hash #include<iostream> #include<cst ...

  2. sdut oj 2372 Annoying painting tool (【暴力枚举测试】1Y )

    Annoying painting tool 题目描述 Maybe you wonder what an annoying painting tool is? First of all, the pa ...

  3. RequireJS 加载 js 执行顺序

    初次接触RequireJS 对文档理解不很透彻,自己通过测试测到的执行顺序: 文档结构: |-amaze | -js | -amazeui.js | -jquery.min.js | -main.js ...

  4. Vue.js style(内联样式)

    Vue.js style(内联样式) 我们可以在 v-bind:style 直接设置样式: <div id="app"> <div v-bind:style=&q ...

  5. 使用Oracle数据库实现树形结构表的子-父级迭代(递归)查询和删除,通过级联菜单简单举例

    前言: 我们在开发中,常常遇到单表的子-父id级联的表结构,在树形的深度不确定的情况下,一次查询出某个树形结构下的所有具有子-父级关系的数据变得十分困难. 这时,我们使用oracle提供的CONNEC ...

  6. netty学习2

    一.Netty分层设计 Netty 采用了比较典型的三层网络架构进行设计,逻辑架构图如下所示: #第一层,Reactor 通信调度层,它由一系列辅助类完成,包括 Reactor 线程 NioEvent ...

  7. bzoj4247挂饰——DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4247 就是01背包: 把挂钩数限制在n以内,因为不需要更多,而这会带来一些问题,就是有很多挂 ...

  8. hibernate学习二 基本用法

    一  映射文件User.hbm.xml 定义了持久化类实例是如何存储和加载的,这个文件定义了持久化类和表的映射. 根据映射文件,Hibernate可以生成足够的信息以产生所有的SQL语句,也就是类的实 ...

  9. JVM 内存区域

    JVM 将内存区域划分为: Method Area(Non-Heap)(方法区) ,Heap(堆) , Program Counter Register(程序计数器) , VM Stack(虚拟机栈, ...

  10. HDOJ-1021

    Fibonacci Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...