题意:

  求一个数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. 【DP】BZOJ 1260: [CQOI2007]涂色paint

    1260: [CQOI2007]涂色paint Time Limit: 30 Sec  Memory Limit: 64 MBSubmit: 893  Solved: 540[Submit][Stat ...

  2. WPF 资源

    https://wpftoolkit.codeplex.com/documentation http://www.codeproject.com/Articles/563862/Multi-Selec ...

  3. ios开发之网络访问的数据类型

    1> JSON 特点:1. [ ] 表示数组  {} 表示字典 - 对象模型建立关系 2. 应用非常多,基本上移动开发的主要数据传输都是JSON 要使用JSON,从网络上获取到数据data后,直 ...

  4. GCD异步加载网络图片

    //image dispatch_queue_t network_queue; network_queue = dispatch_queue_create("com.myapp.networ ...

  5. Chp5: Bit Manipulation

    Bits Facts and Tricks x ^ 0s =  x x & 0s =  0 x | 0s = x x ^ 1s = ~x x & 1s = x x | 1s = 1s ...

  6. POJ 1716

    #include <iostream> #include <algorithm> #define MAXN 20005 using namespace std; int _m[ ...

  7. Asp.Net缓存(2)

    缓存页的多个版本 ASP.NET 允许在输出缓存中缓存同一页的多个版本.输出缓存可能会因下列因素而异: 初始请求 (HTTP GET) 中的查询字符串. 回发时传递的控制值(HTTP POST 值). ...

  8. BZOJ 1982 Moving Pebbles

    首先我们假设只有两堆, 容易发现当且仅当两堆相等时,先手必败 否则先手必胜 然后我们猜测一下原因: ->当两堆相等时,无论先手怎么做,后手总能使两堆相等,且必败态为0,0 推广一下: 当所有的石 ...

  9. 【Linux高频命令专题(14)】nl

    概述 nl命令在linux系统中用来计算文件中行号.nl 可以将输出的文件内容自动的加上行号!其默认的结果与 cat -n 有点不太一样,nl 可以将行号做比较多的显示设计,包括位数与是否自动补齐 0 ...

  10. AJAX POST请求中参数以form data和request payload形式在servlet中的获取方式

    转载:http://blog.csdn.net/mhmyqn/article/details/25561535 HTTP请求中,如果是get请求,那么表单参数以name=value&name1 ...