意甲冠军: 要求 小于或等于n号码 (0<=n <= 1e18)尾数的数的阶乘0数为偶数

思考:当然不是暴力,因此,从数论。尾数0数为偶数,然后,它将使N阶乘5电源是偶数。(二指数肯定少5指数),乞讨N。阶乘5该指数是N/5+ N/25+N/125。

。。

以530为例。尝试着将转化为5进制  即为 4110。那么5的指数 就是 411+41+4 (5进制)easy发现要使这个数是偶数。就是要使5进制奇数位的个数为偶数。依据刚才那个加法,能够看出,最后结果的5进制的末位就是411+41+4 的末位 即 4+1+1 即为原数最高位到最低第二位每一位的和,末二位依次类推。。。。

那么仅仅要做到这里。。。接下来就是数位DP的事了,DP[pos][parity][presum]

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
vector<int> digit;
#define REP(_,a,b) for(int _ = (a); _ <= (b); _++)
LL dp[30][2][2];
LL n;
LL dfs(int pos,int parity,int sum,bool done) {
if(pos==0) {
if(parity==0) {
int sz = done?digit[pos]:4;
return sz+1;
}else{
return 0;
} }
if(!done && dp[pos][parity][sum] != -1) return dp[pos][parity][sum];
LL ret = 0;
int end = done? digit[pos]:4;
for(int i = 0; i <= end; i++) {
ret += dfs(pos-1,(parity+(sum+i)&1)&1,(sum+i)&1,done&&i==end ) ;
}
if(!done) dp[pos][parity][sum] = ret;
return ret;
}
LL solve(LL n) {
if(n <= 4) return n+1;
memset(dp,-1,sizeof dp);
digit.clear();
while(n) {
digit.push_back(n%5);
n /= 5;
}
return dfs(digit.size()-1,0,0,1);
}
int main(){ while(~scanf("%lld",&n) && n !=-1) {
printf("%lld\n",solve(n));
}
return 0;
}

版权声明:本文博主原创文章。博客,未经同意不得转载。

UVa 12683 Odd and Even Zeroes(数论+数字DP)的更多相关文章

  1. UVA 12683 Odd and Even Zeroes(数学—找规律)

    Time Limit: 1000 MS In mathematics, the factorial of a positive integer number n is written as n! an ...

  2. UVALive - 6575 Odd and Even Zeroes 数位dp+找规律

    题目链接: http://acm.hust.edu.cn/vjudge/problem/48419 Odd and Even Zeroes Time Limit: 3000MS 问题描述 In mat ...

  3. UVA.12716 GCD XOR (暴力枚举 数论GCD)

    UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...

  4. 【bzoj4872】[Shoi2017]分手是祝愿 数论+期望dp

    题目描述 Zeit und Raum trennen dich und mich. 时空将你我分开. B 君在玩一个游戏,这个游戏由 n 个灯和 n 个开关组成,给定这 n 个灯的初始状态,下标为从 ...

  5. 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP)

    layout: post title: 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP) author: "luowentaoaa" catalog: true ...

  6. HDU - 4734 F(x) (2013成都网络游戏,数字DP)

    意甲冠军:求0-B见面<=F[A]所有可能的 思维:数字DP,内存搜索 #include <iostream> #include <cstring> #include & ...

  7. UVa 1640 - The Counting Problem(数论)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. UVA 11246 - K-Multiple Free set(数论推理)

    UVA 11246 - K-Multiple Free set 题目链接 题意:一个{1..n}的集合.求一个子集合.使得元素个数最多,而且不存在有两个元素x1 * k = x2,求出最多的元素个数是 ...

  9. UVa 106 - Fermat vs Pythagoras(数论题目)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

随机推荐

  1. hdu3485(递推)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3485 分析: a[i]表示长度为i,第i位为0的,符合情况的个数. b[i]表示长度为i,第i位为1的 ...

  2. 在阿里云的CentOS环境中安装django

    购买了一台阿里云主机.操作系统为CentOS 6.5.准备在上面跑Django做Web开发.因为CentOS自带的python版本号较低,安装Django先要安装新版本号python.还是费了点周折. ...

  3. hdu 4529 Double Dealing (置换群)

    # include <stdio.h> # include <algorithm> # include <string.h> using namespace std ...

  4. tar.bz2解压

    bzip2 -d gcc-4.1.0.tar.bz2 tar -xvf gcc-4.1.0.tar 或 tar -xvf *.tar

  5. 解决方式:QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins

    在用QSqlDatabase时遇到报错QSqlDatabase: an instance of QCoreApplication is required for loading driver plug ...

  6. .Net C# Windows Service于server无法启动,错误 193:0xc1

    1.情况说明:的近期发展windows维修,当地win7系统正常.把server安装会失败. 图中的引导失败的例子.: 解决方法:执行->输入:eventvwr.msc    打开你的事件查看器 ...

  7. Instruments的使用 逻辑查错,内存泄漏分析等工具集

    原创文章,转载请注明 XCode 开发后期,要对代码进行改进和优化,查内存泄漏是其中一项重要工作,今天下午偷了点时间,把前段时间的代码稍微整理了一下,顺带用了下这个工具,还真发现了些问题.这里记录一下 ...

  8. Golang初学者的资源整理

    看了汪汪汪不是我的语言的GO语言零基础入门资料整理,个人感觉还不够全面,忍不住过来补充一些内容. 网站教程: GO语言编程 and GO语言开发2048 from 实验楼Go语言后台应用开发 form ...

  9. hdu 动态规划(46道题目)倾情奉献~ 【只提供思路与状态转移方程】(转)

    HDU 动态规划(46道题目)倾情奉献~ [只提供思路与状态转移方程] Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955      背包 ...

  10. 转载:ecshop自定义销量

    转自:http://www.phpally.com/ecshop%E8%87%AA%E5%AE%9A%E4%B9%89%E9%94%80%E9%87%8F/ 本补丁以假乱真,对网站销售有一定帮助,计算 ...