G - B-number
#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的更多相关文章
- CF 724 G. Xor-matic Number of the Graph
G. Xor-matic Number of the Graph 链接 题意: 给定一个无向图,一个interesting的三元环(u,v,s)满足,从u到v的路径上的异或和等于s,三元环的权值为s, ...
- 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 ...
- 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个数 ...
- Codeforces 724 G Xor-matic Number of the Graph 线性基+DFS
G. Xor-matic Number of the Graph http://codeforces.com/problemset/problem/724/G 题意:给你一张无向图.定义一个无序三元组 ...
- Codeforces G. Bus Number(dfs排列)
题目描述: Bus Number time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- G - Harmonic Number (II) LightOJ - 1245
算是一个找规律的题目吧. 枚举前sqrt(n)个数,数i出现的次数为n/i-n/(i+1),对答案的贡献为(n/i-n/(i+1))*i. 对于sqrt后边的数,可以直接由n/i获得,并且一定只出现一 ...
- LightOJ 1245 Harmonic Number (II)(找规律)
http://lightoj.com/volume_showproblem.php?problem=1245 G - Harmonic Number (II) Time Limit:3000MS ...
- 华中农业大学第五届程序设计大赛网络同步赛-G
G. Sequence Number In Linear algebra, we have learned the definition of inversion number: Assuming A ...
- hzau 1205 Sequence Number(二分)
G. Sequence Number In Linear algebra, we have learned the definition of inversion number: Assuming A ...
- input属性设置type="number"之后, 仍可输入e, E, -, + 的解决办法
<el-input v-model="scope.row.variables.leaderbuweiscores.score" @keyup.native="cha ...
随机推荐
- Struts多个文件上传
Struts2多个文件上传 10级学员 韩晓爽课堂笔记 多个文件上传分为List集合和数组,下面我们着重介绍一下list集合的上传.都大同小异. 一 介绍 1. 在struts2文件上传的时候要先导入 ...
- Juery插件-- jquery.cookie.js
1.引入jquery <script src="scripts/jquery-1.8.8.js" type="text/javascript">&l ...
- Codeforces Round #222 (Div. 1) Maze —— dfs(连通块)
题目链接:http://codeforces.com/problemset/problem/377/A 题解: 有tot个空格(输入时统计),把其中k个空格变为wall,问怎么变才能使得剩下的空格依然 ...
- WebDriver API——javascript的相关操作
有些时候webdriver是没法操作元素或浏览器的,这时候我们可以通过javascript来进行相关的操作,昨天在群里一个朋友定位一个显示框,总是无法定位点击,或者是点击无效,这个时候就可以用java ...
- codeforces B. Trees in a Row 解题报告
题目链接:http://codeforces.com/problemset/problem/402/B 题目意思:给出n个数和公差k,问如何调整使得ai + 1 - ai = k.(1 ≤ i < ...
- ubuntu nginx 安装 certbot(letsencrypt)
https://certbot.eff.org 到上面网站按照步骤安装certbot, 安装完成后,certbot 生成证书有两种方式 第一种:standalone模式,certbot 会启动自带的n ...
- 运行swoole_server方法
运行 php 文件 server.php 运行结果是如下: 只是服务器开启了 如果想看客户端连接的情况 可以测试一下 从新连接一个连接 用命令 方式 telnet 127.0.0.1 9501 这个9 ...
- 不能访问tomcat中的项目
tomcat在eclipse里面能正常启动,而在浏览器中访问http://localhost:8080/不能访问,且报404错误.同时其他项目页面也不能访问. 关闭eclipse里面的tomcat,在 ...
- 算法实现c语言--03
实现 mystrcpy(), mystrcmp(), mystrcat(), mystrlen() ; #include<stdio.h> #include<stdlib.h> ...
- 创建calico网络报错client response is invalid json
使用docker创建calico网络失败. # docker network create --driver calico --ipam-driver calico-ipam testcalico E ...