题意:

  求一个数n的阶乘,其往后数第1个不是0的数字是多少。

思路:

  [1,n]逐个乘,出现后缀0就过滤掉,比如12300就变成123,继续算下去。为解决爆long long问题,将其余一个数mod,过滤掉前面过大的部分,因为计算出来也没用。这个mod应该是多少? 10亿就行。

 #include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N=;
const int mod=;
int ans[N]; void init()
{
LL fun=;
ans[]=;
for(int i=; i<N; i++)
{
fun*=i;
while(fun%==)
fun/=; //过滤掉后缀0
ans[i]=fun%; //取最后一位
fun%=mod;
}
} int main()
{
//freopen("input.txt", "r", stdin);
init();
int a;
while(~scanf("%d",&a))
printf("%5d -> %d\n",a,ans[a]);
return ;
}

AC代码

UVA 568 Just the Facts (水)的更多相关文章

  1. UVa 568 - Just the Facts

    这道题和这几段牛代码让我见识了精简与高效.好好学习! http://blog.csdn.net/lyhvoyage/article/details/9307009

  2. uva 10252 - Common Permutation 字符串水题

    题意:給定兩個小寫的字串a與b,請印出皆出現在兩字串中的字母,出現的字母由a~z的順序印出,若同字母出現不只一次,請重複印出但不能超過任一字串中出現的次數.(from Ruby兔) 很水,直接比较输出 ...

  3. uva 489 Hangman Judge(水题)

    题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...

  4. UVA 568 (13.07.28)

     Just the Facts  The expression N!, read as `` N factorial," denotes the product of the first N ...

  5. UVa 10340 - All in All 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  6. UVa 11636 Hello World! (水题思维)

    题意:给你一个数,让你求需要复制粘贴多少次才能达到这个数. 析:这真是一个水题,相当水,很容易知道每次都翻倍,只要大于等于给定的数就ok了. 代码如下: #include <iostream&g ...

  7. UVA 11947 Cancer or Scorpio 水题

    Cancer or Scorpio Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://uva.onlinejudge.org/index.php? ...

  8. UVA 11100 The Trip, 2007 水题一枚

    题目链接:UVA - 11100 题意描述:n个旅行箱,形状相同,尺寸不同,尺寸小的可以放在尺寸大的旅行箱里.现在要求露在最外面的旅行箱的数量最少的同时满足一个旅行箱里放的旅行箱的数量最少.求出这样满 ...

  9. UVA 11461 - Square Numbers 数学水题

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

随机推荐

  1. jquery(1.3.2)<--json-->spring(3.0)

    发现spring 3已经对ajax支持的很好了,前端可以只使用html+jquery,后端 只使用spring再加上一种orm,两者之间用json交换数据就可以了,现在是放弃 jsp,struts这些 ...

  2. isEmpty()与equals()、==“”区别

    isEmpty方法源码:public static boolean isEmpty(String str) { return (str == null) || (str.length() == 0); ...

  3. Unity3D Development模式下的一个小问题

    今天客户提交了一个反馈,说测试版本的应用在按下电源键的时候屏幕变黑,然后重新按下电源键启动的时候发现没有出现屏幕锁屏的情况,直接回到应用界面. 我这边看了一下,发现如果装了360之类的手机助手就没这个 ...

  4. php浮点数精确运算

    php浮点数精确运算 Php: BCMath bc是Binary Calculator的缩写.bc*函数的参数都是操作数加上一个可选的 [int scale],比如string bcadd(strin ...

  5. StringBuffer用法

    public class StringBufferTest { public static void main(String[] args) { StringBuffer sb=new StringB ...

  6. grunt安装失败处理

    1.官网 Grunt官网 http://gruntjs.com 2.前言 前段时间一不小心升级了win10(万恶的360),各种不适应各种问题各种软件bug,最终决定回退到win7,然后悲催的发现系统 ...

  7. Oracle 6 - 锁

    Oracle锁没有额外的开销?Oracle的锁是怎么实现的?因为其他数据库,锁都是一种稀有资源和开销. 答:代码级实现?? 没有锁的话,并发更新就会有丢失更新的问题. 悲观锁和乐观锁 悲观锁一般用于有 ...

  8. maven 环境搭建 Myeclipse配置

    一:Maven的下载安装 准备工作: 1)安装环境 Windows xp 2)需安装JDK ,并配置环境变量(略) 3) Maven版本3.0.5 4)下载地址:http://mirror.bit.e ...

  9. java:接口实例

    接口:打印机接口 interface Printer { public void read(); } 函数一:佳能打印机 class CanPrinter implements Printer { p ...

  10. Java解压上传zip或rar文件,并解压遍历文件中的html的路径

    1.本文只提供了一个功能的代码 public String addFreeMarker() throws Exception { HttpSession session = request.getSe ...