题解 UVA10212 【The Last Non-zero Digit.】
这题在学长讲完之后和看完题解之后才明白函数怎么构造。
这题构造一个$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.】的更多相关文章
- 题解报告:hdu 1060 Leftmost Digit
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060 问题描述 给定一个正整数N,你应该输出N ^ N的最左边的数字. 输入 输入包含多个测试用例. ...
- 题解报告:hdu 1061 Rightmost Digit(快速幂取模)
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...
- UVA10212 【The Last Non-zero Digit.】
暴力可做!!!(十秒还不打暴力!!!)暴力算阶乘边算边取余上代码 #include<iostream> #define int long long //开long long using n ...
- LeetCode Next Greater Element III
原题链接在这里:https://leetcode.com/problems/next-greater-element-iii/description/ 题目: Given a positive 32- ...
- 【题解】Digit Tree
[题解]Digit Tree CodeForces - 716E 呵呵以为是数据结构题然后是淀粉质还行... 题目就是给你一颗有边权的树,问你有多少路径,把路径上的数字顺次写出来,是\(m\)的倍数. ...
- luoguP1118 [USACO06FEB]数字三角形`Backward Digit Su`… 题解
一上午都在做有关搜索的题目,,, 看到这题之后就直接开始爆搜 结果只有70分, 其余的点硬生生的就是那么WA了. 我的天哪~ 70分代码: #include<iostream> #incl ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- HD1060Leftmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission( ...
- 233. Number of Digit One
题目: Given an integer n, count the total number of digit 1 appearing in all non-negative integers les ...
随机推荐
- 【整理】Android中的gravity和layout_gravity区别
[背景] 在Android中,想要设置个按钮的水平对齐,都累死了: [已解决]ADT中已设置TableLayout布局的情况下如何设置按钮居中对齐 所以现在有必要搞清楚,到底gravity和la ...
- PHP PDO SQLSERVER
$bbs = new PDO("odbc:MSSQLServer", $username_bbs, $password_bbs $bbs = new PDO('); $s ...
- Java如何解决form表单上传文件,以及页面返回处理结果通知!
前端JSP代码 <form id='formSumbit' class='form-horizontal' action='/ncpay/route/chlsubmcht/batchImpor' ...
- Full Binary Tree(sdut 2882)
Problem Description: In computer science, a binary tree is a tree data structure in which each node ...
- GCC 常见参数配置
博客转载自:https://www.cnblogs.com/zhangsir6/articles/2956798.html 简介gcc and g++现在是gnu中最主要和最流行的c & c+ ...
- Apache htdigest命令
一.简介 htdigest命令是Apache的Web服务器内置工具,用于创建和更新储存用户名.域和用于摘要认证的密码文件.服务器上的资源可以被限制为仅允许由htdigest建立的文件中的用户访问.使用 ...
- Python pip命令
一.简介 pip 是一个安装和管理 Python 包的工具 , 是 easy_install 的一个替换品.distribute是setuptools的取代(Setuptools包后期不再维护了),p ...
- python操作Redis缓存
python操作Redis缓存 https://www.cnblogs.com/guotianbao/p/8683037.html 学习资料:电子书资源 联系邮箱:gmu1592618@gmail.c ...
- cbv+resful+APIView源码分析
CBV源码分析 1概念:什么是cbv和fbv 已经什么是API class bass View ---基于类的视图 function bass View ---基于函数的视图 API(Applicat ...
- 在使用webstorm打开本地项目文件夹的html文件时,浏览器提示404错误
错误原因:在使用webstorm打开本地项目文件夹的html文件时,浏览器提示404错误. 错误分析:文件夹命名内包含“+”,此特殊符号导致浏览器解析错误. 改正方案:去掉特殊符号“+”