N的阶乘HDOJ1042
我记得有一份代码是非常有技巧的,然而这一份就是很死板…每次跑50000,因为10000的阶乘最多才50000位,这样肯定就过了
#include<cstdio>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=50000;
int f[maxn+1];
int main()
{
int n,c,k;
while(~scanf("%d",&n))
{
memset(f,0,sizeof(f));
f[0]=1;
for(int i=1;i<=n;i++)
{
c=0; //代表进位
for(int j=0;j<=maxn;j++)
{
int s=f[j]*i+c;
f[j]=s%10;
c=s/10;
}
}
for(k=maxn;k>=0;k--)
if(f[k]) break;
for(int j=k;j>=0;j--)
cout<<f[j];
cout<<endl;
}
return 0;
}
N的阶乘HDOJ1042的更多相关文章
- HDoj-1042 大数阶乘
N! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- C语言 · 阶乘计算 · 基础练习
问题描述 输入一个正整数n,输出n!的值. 其中n!=1*2*3*-*n. 算法描述 n!可能很大,而计算机能表示的整数范围有限,需要使用高精度计算的方法.使用一个数组A来表示一个大整数a,A[0]表 ...
- Java 计算N阶乘末尾0的个数-LeetCode 172 Factorial Trailing Zeroes
题目 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in ...
- 关于for循环的几个小练习,例如奇数偶数,阶乘,求和等
1 .100以内的奇数和偶数 var js = ""; var os = ""; for(var i=1;i<101;i++) { if(i%2 == 0 ...
- [LeetCode] Factorial Trailing Zeroes 求阶乘末尾零的个数
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- 求单链表L各结点的阶乘之和(c语言)
链表需要用到指针 阶乘需要用到递归 链表中的注意事项: 1.链表L是否等于NULL ----------是循环结束的条件 2.链表L->Data ---------取链表L中各个结点的值 3.L ...
- 洛谷 P2726 阶乘 Factorials Label:Water
题目背景 N的阶乘写作N!,表示小于等于N的所有正整数的乘积. 题目描述 阶乘会变大得很快,如13!就必须用32位整数类型来存储,到了70!即使用浮点数也存不下了. 你的任务是找到阶乘最前面的非零位. ...
- js实现阶乘
//while循环实现function calNum(n) { var product = 1; while(n > 1){//1*5*4*3*2,1*n*(n-1)*(n-2)*...*2 p ...
- 洛谷P1134 阶乘问题[数论]
题目描述 也许你早就知道阶乘的含义,N阶乘是由1到N相乘而产生,如: 12! = 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 x 12 = 479,001, ...
随机推荐
- 高速清除winXP系统中explorer.exe病毒
关于这个explorer.exe病毒.是眼下xp最为常见的一个病毒,会大量的消耗系统资源,造成电脑特别的卡顿. 1.关闭还原(假设没有,则跳过),为的是防止我们改动后,还原之后又回来了. 2.打开注冊 ...
- ng-options bug解决方案(示例)
情况: 无法获取 ng-model 的值 解决方案: 绑定到对象的属性值上 1.页面 <ion-view hide-nav-bar="true"> <ion-co ...
- free命令具体解释——Linux性能分析
一.使用格式 语法格式:free [-b | -k | -m] [-o] [-s delay ] [-t] [-l] [-V] [-b | -k | -m] :选择数据的单位-b字节.-k千字节.-m ...
- 【Leetcode】经典的Jump Game in JAVA
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- mysql 查询 优化
1.基本原则:优化数据访问 (1)是否想服务器请求了不需要的数据?提取超过需要的列,多表连接时提取所有列,提取所有列都会消耗不必要的资源,提取你所需要的列就可以了. (2)MySQL检查了太多的数据吗 ...
- linux块设备驱动(一)——块设备概念介绍
本文来源于: 1. http://blog.csdn.net/jianchi88/article/details/7212370 2. http://blog.chinaunix.net/uid-27 ...
- c# 连接各种数据库 Access、Server等
1.C#连接连接Access程序代码: using System.Data;using System.Data.OleDb;..string strConnection="Provider= ...
- TButton.Repaint的执行过程
测试,在按钮事件里写上 Button1.Repaint;(包括TWinControl.Invalidate;和procedure TWinControl.Update;两个函数,会被TButton所继 ...
- console调试命令
一.显示信息的命令 <!DOCTYPE html> <html> <head> <title>常用console命令</title> < ...
- java 相关博客
Intellij Idea 创建Web项目入门(一) SpringMVC 和 MyBatis 学习笔记,搭配示例,主要讲解一些基础的概念.用法和配置 包含框架有:SpringMVC.MyBaits.A ...