题目链接

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

这题构造一个$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. 不用jquery实现tab页切换,刷新,后退,前进状态自动维护 很好用

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. leetcode669

    本题目是使用递归处理,根据当前的值来判断剪去的子树,保留剩下的子树. class Solution { public: TreeNode* trimBST(TreeNode* root, int L, ...

  3. 微信公众号php从0开发,包括功能(自定义菜单,分享)

    之前写的一篇微信公众号文章. 工作需要,进行此次调研,并记录开发过程. 开发目的,页面授权,页面获取用户头像,用户昵称 微信id, 分享页面. 微信订阅号 无法获取用户个人信息 写在记录前,公众号也是 ...

  4. WPF TabItem.Collapse 的问题

    WPF TabItem.Collapse 的问题 运行环境:Window7 64bit,.NetFramework4.61,C# 6.0: 编者:乌龙哈里 2017-02-16 感谢 LICEcap ...

  5. Hadoop IO基于文件的数据结构详解【列式和行式数据结构的存储策略】

    Charles所有关于hadoop的文章参考自hadoop权威指南第四版预览版 大家可以去safari免费阅读其英文预览版.本人也上传了PDF版本在我的资源中可以免费下载,不需要C币,点击这里下载. ...

  6. selenium+phantomjs解析JS

    背景知识: PhantomJS 是一个基于WebKit的服务器端 JavaScript API.它全面支持web而不需浏览器支持,其快速,原生支持各种Web标准: DOM 处理, CSS 选择器, J ...

  7. nmap 笔记

    本文由阿德马翻译自国外网站,请尊重劳动成果,转载请注明出处,谢谢 1.初级用法: 教程   Nmap使用不同的技术来执行扫描,包括:TCP的connect()扫描,TCP反向的ident扫描,FTP反 ...

  8. Storm的wordCounter计数器详解

    原文:http://www.maoxiangyi.cn/index.php/archives/362 拓扑 点击(此处)折叠或打开 package cn.jd.storm; import backty ...

  9. 使用dockerfile-maven-plugin发布docker到私有仓库

    要想拥有私有docker仓库,需要安装registry镜像,最新版时2.0,具体可以看文档:https://docs.docker.com/registry/. 1. docker pull regi ...

  10. redis系列:基于redis的分布式锁

    一.介绍 这篇博文讲介绍如何一步步构建一个基于Redis的分布式锁.会从最原始的版本开始,然后根据问题进行调整,最后完成一个较为合理的分布式锁. 本篇文章会将分布式锁的实现分为两部分,一个是单机环境, ...