题目链接

这题在学长讲完之后和看完题解之后才明白函数怎么构造。

这题构造一个$f(n)$

$f(n)$ $=$ $n$除以 $2^{a}$ $*$ $5^{b}$ ,$a$ , $b$ 分别是 $n$ 质因数分解后$2,5$的个数。

然后就暴力算一算就好了。

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
//处理出来n的质因子中,x的个数。
int prime(int n,int x)
{
int res=;
while(n) res+=n/x,n/=x;
return res;
}
//f(1)到f(n)中不以5结尾的奇数的个数
int expect_5_end_odd(int n,int x)
{
if(!n) return ;
return n/+(n%>=x)+expect_5_end_odd(n/,x);
}
//以5结尾的数的个数。
int expect_5_end(int n,int x)
{
if(!n) return ;
return expect_5_end(n/,x)+expect_5_end_odd(n,x);
} int t[][]={
,,,,//2^4 2 2^2 2^3 的最后一位
,,,,//3^4 3 3^2 3^3 的最后一位
,,,,//4……
,,,//5……
}; signed main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
m=n-m;
int prime_2=prime(n,)-prime(m,);
int prime_3=expect_5_end(n,)-expect_5_end(m,);
int prime_5=prime(n,)-prime(m,);
int prime_7=expect_5_end(n,)-expect_5_end(m,);
int prime_9=expect_5_end(n,)-expect_5_end(m,); if(prime_2<prime_5){puts("");continue;} int res=;
if(prime_2>prime_5) res*=t[][(prime_2-prime_5)%];
res=res*t[][prime_3%]*t[][prime_7%]*t[][prime_9%]%;
printf("%lld\n",res);
}
return ;
}

题解 UVA10212 【The Last Non-zero Digit.】的更多相关文章

  1. 题解报告:hdu 1060 Leftmost Digit

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060 问题描述 给定一个正整数N,你应该输出N ^ N的最左边的数字. 输入 输入包含多个测试用例. ...

  2. 题解报告:hdu 1061 Rightmost Digit(快速幂取模)

    Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...

  3. UVA10212 【The Last Non-zero Digit.】

    暴力可做!!!(十秒还不打暴力!!!)暴力算阶乘边算边取余上代码 #include<iostream> #define int long long //开long long using n ...

  4. LeetCode Next Greater Element III

    原题链接在这里:https://leetcode.com/problems/next-greater-element-iii/description/ 题目: Given a positive 32- ...

  5. 【题解】Digit Tree

    [题解]Digit Tree CodeForces - 716E 呵呵以为是数据结构题然后是淀粉质还行... 题目就是给你一颗有边权的树,问你有多少路径,把路径上的数字顺次写出来,是\(m\)的倍数. ...

  6. luoguP1118 [USACO06FEB]数字三角形`Backward Digit Su`… 题解

    一上午都在做有关搜索的题目,,, 看到这题之后就直接开始爆搜 结果只有70分, 其余的点硬生生的就是那么WA了. 我的天哪~ 70分代码: #include<iostream> #incl ...

  7. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  8. HD1060Leftmost Digit

      Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission( ...

  9. 233. Number of Digit One

    题目: Given an integer n, count the total number of digit 1 appearing in all non-negative integers les ...

随机推荐

  1. 使用airodump-ng扫描网络

    执行命令 root@sch01ar:~# airodump-ng wlan0mon 参数介绍: BSSID:表示无线AP的Mac地址 PWR:网卡报告的信号水平 Beacons:无线AP发出的通告编号 ...

  2. vue-cli中的ESlint配置文件eslintrc.js详解

    本文讲解vue-cli脚手架根目录文件.eslintrc.js eslint简介 eslint是用来管理和检测js代码风格的工具,可以和编辑器搭配使用,如vscode的eslint插件 当有不符合配置 ...

  3. linux下编译wpa_supplicant&nbsp;…

    linux下编译wpa_supplicant 收藏 前一段时间只在vs2005下编译成功过.经过近一段时间的琢磨,今天终于在linux下成功编译了wpa_supplicant. 挺简单的事情折腾了这么 ...

  4. json和pickle序列化模块

    一.json序列化模块 1.序列化:将内存数据转成字符串加以保存. 2.反序列化:将字符串转成内存数据加以读取. data = { '北京':{ '五道口':{ 'sohu':'引擎', } } } ...

  5. (三)maven出错记录

    此处因为是自己做的所以文笔带过,简单描述下 1\首先是jsp页面报错,缺少必要的servletx依赖jar包,需要在pom中配置 <dependency><groupId>ja ...

  6. 自制模仿apache访问日志文件格式的php日志类

    <?php // 访问日志写入类 @author 王伟 2011.12.14class Log{        //项目跟路径    private $root_path;        //日 ...

  7. coordinatewise 是什么意思?

    As far as I remember, in the context of optimization, "coordinate wise" means that you are ...

  8. 9.python 系统批量运维管理器之Fabric模块

    前面介绍了paramiko,pexpect模块,今天来说比较适合大型应用自动化部署的模块,或者执行系统命令的模块Fabric. Fabric 是一个 Python 的库,同时它也是一个命令行工具.它提 ...

  9. 第08章-使用Spring Web Flow

    使用Spring Web Flow Spring Web Flow是Spring MVC的扩展,它支持开发基于流程的应用程序.它将流程的定义与实现流程行为的类和视图分离开来. 1 在Spring中配置 ...

  10. 编写高质量代码改善C#程序的157个建议——建议56:使用继承ISerializable接口更灵活地控制序列化过程

    建议56:使用继承ISerializable接口更灵活地控制序列化过程 接口ISerializable的意义在于,如果特性Serializable,以及与其像配套的OnDeserializedAttr ...