UVA 568 Just the Facts (水)
题意:
求一个数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 (水)的更多相关文章
- UVa 568 - Just the Facts
这道题和这几段牛代码让我见识了精简与高效.好好学习! http://blog.csdn.net/lyhvoyage/article/details/9307009
- uva 10252 - Common Permutation 字符串水题
题意:給定兩個小寫的字串a與b,請印出皆出現在兩字串中的字母,出現的字母由a~z的順序印出,若同字母出現不只一次,請重複印出但不能超過任一字串中出現的次數.(from Ruby兔) 很水,直接比较输出 ...
- uva 489 Hangman Judge(水题)
题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...
- UVA 568 (13.07.28)
Just the Facts The expression N!, read as `` N factorial," denotes the product of the first N ...
- UVa 10340 - All in All 水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 11636 Hello World! (水题思维)
题意:给你一个数,让你求需要复制粘贴多少次才能达到这个数. 析:这真是一个水题,相当水,很容易知道每次都翻倍,只要大于等于给定的数就ok了. 代码如下: #include <iostream&g ...
- UVA 11947 Cancer or Scorpio 水题
Cancer or Scorpio Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://uva.onlinejudge.org/index.php? ...
- UVA 11100 The Trip, 2007 水题一枚
题目链接:UVA - 11100 题意描述:n个旅行箱,形状相同,尺寸不同,尺寸小的可以放在尺寸大的旅行箱里.现在要求露在最外面的旅行箱的数量最少的同时满足一个旅行箱里放的旅行箱的数量最少.求出这样满 ...
- UVA 11461 - Square Numbers 数学水题
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
随机推荐
- web服务器和应用服务器
通俗的讲,Web服务器传送(serves)页面使浏览器可以浏览,然而应用程序服务器提供的是客户端应用程序可以调用(call)的方法(methods).确切一点,你可以说:Web服务器专门处理HTTP请 ...
- 提升SQL Server速度整理索引碎片
转载:http://wenku.baidu.com/view/f64c8a707fd5360cba1adbea.html SQL Server2005索引碎片分析和解决方法 毫无疑问,给表添加索引 ...
- uva 991
卡特兰数 最后不输出空行... #include <cstdio> #include <cstdlib> #include <cmath> #include &l ...
- cf 363D
贪心加二分 虽然比赛后才过 ........ /************************************************************************* &g ...
- uva 11235
数据结构 RMQ算法 左右左右 写得有点晕了 ..... /****************************************************************** ...
- Finite State Machine
Contents [hide] 1 Description 2 Components 3 C# - FSMSystem.cs 4 Example Description This is a Dete ...
- css ul li 制作导航条
<html> <head> <style> .test ul{list-style:none;} .test li{float:left; width:100px; ...
- 跨线程调用控件之MethodInvoker
原文:http://www.cnblogs.com/cm8448940/archive/2008/07/10/1240045.html 使用到两个控件,一个按钮button1,一个标签label1. ...
- linux源码阅读笔记 jmpi指令(转)
jmpi是段间跳转指令,用于x86实模式下, 如:BOOTSEG = 0x0c70 jmpi 4, #BOOTSEG 假如当前段CS==00h,那么执行此指令后将跳转到段CS==0x0c70,当 ...
- Linux之SAMBA共享服务
简述 Samba服务器可以让Windows操作系统用户访问局域网中Linux主机,就象访问网上邻居一样方便. 具有以下功能: 共享目录:在局域网上共享某个或某些目录,使得同一个网络内的Windows用 ...