Last non-zero Digit in N!(阶乘最后非0位)
Last non-zero Digit in N!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5861 Accepted Submission(s): 1451
For this problem, you are to write a program that can compute the last non-zero digit of the factorial for N. For example, if your program is asked to compute the last nonzero digit of 5!, your program should produce "2" because 5! = 120, and 2 is the last nonzero digit of 120.
2
26
125
3125
9999
2
4
8
2
8
- #include <iostream>
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #define MAXN 10000
- int lastdigit(char* buf){
- const int mod[]={,,,,,,,,,,,,,,,,,,,};
- int len=strlen(buf),a[MAXN],i,c,ret=;
- if (len==)
- return mod[buf[]-''];
- for (i=;i<len;i++)
- a[i]=buf[len--i]-'';
- for (;len;len-=!a[len-]){
- ret=ret*mod[a[]%*+a[]]%;
- for (c=,i=len-;i>=;i--)
- c=c*+a[i],a[i]=c/,c%=;
- }
- return ret+ret%*;
- }
- int main()
- {
- char a[]="\0";
- while(scanf("%s",a)!=EOF)
- {
- int ans=lastdigit(a);
- printf("%d\n",ans);
- }
- return ;
- }
Last non-zero Digit in N!(阶乘最后非0位)的更多相关文章
- NYOJ1026 阶乘末尾非0 【模板】
阶乘末尾非0 时间限制:2000 ms | 内存限制:65535 KB 难度:3 描写叙述 我们的问题非常是简单.n! 末尾非0数是几? 比方n=5的时候,n! =120,那么n!末尾非0数是2. ...
- 计算阶乘n!末尾0的个数
一.问题描述 给定一个正整数n,请计算n的阶乘n!末尾所含有“0”的个数.例如: 5!=120,其末尾所含有的“0”的个数为1: 10!= 3628800,其末尾所含有的“0”的个数为2: 20!= ...
- N阶乘尾部的0个数
N阶乘尾部的0个数 描述 设计一个算法,计算出n阶乘中尾部零的个数 思路: 1.1 * 2 * 3 * ... * n --> 1 * 2 * 3 * (2 * 2) * 5 * (2 * 3) ...
- Rightmost Digit (求n^n最后一位)
Description Given a positive integer N, you should output the most right digit of N^N. Input The ...
- POJ 1401:Factorial 求一个数阶乘的末尾0的个数
Factorial Time Limit: 1500MS Memory Limit: 65536K Total Submissions: 15137 Accepted: 9349 Descri ...
- HDU 1060 Leftmost Digit(求N^N的第一位数字 log10的巧妙使用)
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 2018年东北农业大学春季校赛 E 阶乘后的0【数论】
链接:https://www.nowcoder.com/acm/contest/93/E来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言52428 ...
- 笔试算法题(33):烙饼排序问题 & N!阶乘十进制末尾0的个数二进制最低1的位置
出题:不同大小烙饼的排序问题:对于N块大小不一的烙饼,上下累在一起,由于一只手托着所有的饼,所以仅有一只手可以翻转饼(假设手足够大可以翻转任意块数的 饼),规定所有的大饼都出现在小饼的下面则说明已经排 ...
- acm算法模板(1)
1. 几何 4 1.1 注意 4 1.2 几何公式 4 1.3 多边形 6 1.4 多边形切割 9 1.5 浮点函数 10 1.6 面积 15 1.7 球面 16 1.8 三角形 17 1.9 三维几 ...
随机推荐
- sql server 查询和Kill死锁进程
查询死锁进程语句 select request_session_id spid, OBJECT_NAME(resource_associated_entity_id) tab ...
- UIWebView显示乱码问题
今天有人问Swift中UIWebView加载页面出来的是乱码,问知道怎么解决么? OC我知道肯定不会有乱码问题,Swift就不知道了,因为没有试过.....于是...我自己动手试试啦... OC和Sw ...
- 利用Unity制作“表”
一枚小菜鸟 目前没发现在Unity有其他路径制作类似于c# WinForm中的表:但是利用Unity自带的UGUI,制作了一张"伪表",具体方案如下: 效果图如下: 步骤: 1 ...
- Android 7.0 UICC 分析(一)
UICC(Universal Intergrated Circuit Card) 框架 * Following is class diagram for uicc classes: * * UiccC ...
- 第四十四章 微服务CICD(6)- gitlab + jenkins + docker + k8s
总体流程: 在开发机开发代码后提交到gitlab 之后通过webhook插件触发jenkins进行构建,jenkins将代码打成docker镜像,push到docker-registry 之后将在k8 ...
- UiAutomator自动化测试框架介绍
UiAutomator自动化测试框架介绍 环境搭建 1 必要条件 1.1 JDK 1.2 SDK(API高于15) 1.3 Eclipse 2 ...
- 使用selenium控制滚动条(非整屏body)
方法原理: (1)使用jQuery CSS 操作 - scrollTop() 方法,设置 <div> 元素中滚动条的垂直偏移,语法:$(selector).scrollTop(of ...
- Window 命令
tracert XXX.XXX.XXX.XXX 路由追踪命令,可以显示到目的IP所经过的路由
- mount: unknown filesystem type 'ntfs'
mount: unknown filesystem type 'ntfs' 问题描述 # mount –t ntfs /dev/sdc1 /mnt/usb2 mount: unknown filesy ...
- Tp field 字段是可以添加函数的
$info = M('Order')->alias('a') ->field('count(DISTINCT(a.order_user_id)) as buy_user_num,count ...