题解 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 ...
随机推荐
- python's ninth day for me
函数 函数的定义与调用: #def 关键字 定义一个函数. # my_len 函数名, 函数名的书写规则与变量的命名一致. # def 与函数名中间一个空格. # 函数名() : 加上冒号. ...
- leetcode12
public class Solution { public string IntToRoman(int num) { string[] M = { "", "M&quo ...
- 虚拟机之 搭建discuz论坛
1.下载 mkdir /data/www cd !$ wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_GBK.zip 2.解压 ...
- C++加载位图跟SOCKET通信的编写
//将屏幕信息转换为位图结构 CDC *pDeskDC=GetDesktopWindow()->GetDC();//获取桌面的额画图对象 ; ; CDC memDC;//定义一个内存画布 mem ...
- Python代码的编译
Python代码的编译 Python代码在解释执行之前,是会被编译成.pyc或者.pyo文件的,它们是中间字节码表示的文件,之后Python虚拟机才会去解释执行它们. 1.pyc文件 ======== ...
- Android剖析和运行机制
Android剖析和运行机制 大纲: 1. Android剖析 Linux内核本地库(Native Libraries)Android运行时(Android Runtime)应用框架 2. Andro ...
- jquery中的cookie使用
一.检测cookie是否启用 通过navigator.cookieEnabled这个属性实现,若该值为true,则当前cookie是启用的,反之是禁用的,注意:此属性不是一个标准的属性 二.cooki ...
- mongo_1 新手之路
mongodb 进入.在bin目录下 至于安装各位自己查资料吧 .不废话了 直接上图.这种表示已经成功进入mongo 本人mongo 数据库存放地址.如有需要可以清空可以自己删除. 接下来就是 ...
- - description 方法作用
自定义一个Person类 @interface Person : NSObject { int _age; double _height; double _weight; NSString *_nam ...
- 使用clr 调用C#编写的dll中的方法的全解释
使用clr 调用C#编写的dll中的方法的全解释1.数据库初始化:将下面这段代码直接在运行就可以初始化数据库了exec sp_configure 'show advanced options', '1 ...