UVA 623 - 500!

算法竞赛入门经典经典例题及习题题解 Github仓库 有些例题没找到完全相同的题目,找了类似的。 文章目录算法竞赛入门经典第一版第5章 基础题目选解5.1 字符串5.2 高精度计算5.3 排序与检索5.4 数学基础第六章 数据结构基础6.1 栈和队列6.2 链表6.3 二叉树6.4 图第七章 暴力求解法7.1 简单枚举7.2 枚举排列7.3 子集生成7.4 回溯法7.5 隐式树的遍历第八章 高效算法设计8.1 算法初步分析8.2 再... 阅读详情

In these days you can more and more often happen to see programs which perform some useful calculations being executed rather then trivial screen savers. Some of them check the system message queue and in case of finding it empty (for examples somebody is editing a file and stays idle for some time) execute its own algorithm.

As an examples we can give programs which calculate primary numbers.


One can also imagine a program which calculates a factorial of given numbers. In this case it is the time complexity of order O(n) which makes troubles, but the memory requirements. Considering the fact that 500! gives 1135-digit number no standard, neither integer nor floating, data type is applicable here.


Your task is to write a programs which calculates a factorial of a given number.

Assumptions: Value of a number ``n" which factorial should be calculated of does not exceed 1000 (although 500! is the name of the problem, 500! is a small limit).

Input 

Any number of lines, each containing value ``n" for which you should provide value of n!

Output 

2 lines for each input case. First should contain value ``n" followed by character `!'. The second should contain calculated value n!.

Sample Input 

10
30
50
100

Sample Output 

10!
3628800
30!
265252859812191058636308480000000
50!
30414093201713378043612608166064768844377641568960512000000000000
100!
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000


模拟乘法,预先计算好所有阶乘


#define RUN
#ifdef RUN

#include<stdio.h>
#include<string.h>
const int maxn = 3000;
int f[1000][maxn];
int tmp[maxn];


void printout(){
	for(int i=0; i<1000; i++){
		for(int j=0; j<maxn; j++){
			printf("%d", f[i][j]);
		}
		printf("\n");
	}
}

void init(){
	memset(f, 0, sizeof(f));
	memset(tmp, 0, sizeof(tmp));

	f[0][0] = 1;
	tmp[0] = 1;
	int i;
	for(i = 2; i <= 1000; i++) {
		int c = 0;
		for(int j = 0; j < maxn; j++) {
			int s = tmp[j] * i + c;
			tmp[j] = s % 10;
			c = s / 10;
		}
		memcpy(f[i-1], tmp, sizeof(tmp));
	}

	//printout();
}


int main() {

#ifndef ONLINE_JUDGE
	freopen("623.in", "r", stdin);
	freopen("623.out", "w", stdout); 
#endif

	int i, j, n;
	init();
	
	while(scanf("%d", &n) == 1){

		printf("%d!\n", n);

		if(n == 0){
			printf("1");
		}
		else{
			for(j = maxn-1; j >= 0; j--) if(f[n-1][j]) break;
			for(i = j; i >= 0; i--) printf("%d", f[n-1][i]);
		}

		printf("\n");
	}

	
	return 0;
}


#endif




【2026-Spark实验一-Windows中安装Spark环境】 本文详细介绍了在Windows系统中配置Spark 3.5.8开发环境的完整流程。主要内容包括:安装JDK 8并配置环境变量,下载并解压Spark 3.5.8预编译版,设置SPARK_HOME系统变量,配置Hadoop的winutils工具解决Windows兼容性问题。通过spark-shell和SparkPi示例程序验证环境配置成功,确保Spark能够正常运行分布式计算任务。文中特别强调了路径命名规范、环境变量设置顺序等关键细节,提供了完整的配置截图和验证方法,帮助开发者快速搭建稳定的Spark学习环境。 阅读详情

相关推荐

OrthoFinder功能、流程和文件注释

OrthoFinder 的标准输出包括:直系同源组,直系同源基因,有根基因树,解析基因树,无根物种树、有根物种树,基因重复事件以及相关的统计数据。

hs6605015的博客 3046

UVa623:500!

UVa623:500! 题目大意 简单粗暴,给定正整数n,计算 n! 并输出,这里n最大为1000。 Solution1(naive) 因为阶乘的数值会非常大,所以需要大整数类的支持,一个简单粗暴的想法是利用java中的BigInteger类,这个类已经实现了大整数的所有操作。这种做法很简单直接,但运行速度会稍慢。 AC-Code(Java) Time:450ms import java....

weixin_30614587的博客 138

Buck电路中自举电容串联小电阻的作用

在Buck电路中,自举电容(Cboot)驱动高边MOSFET时,因寄生电感和电容会形成LC谐振回路,导致SW节点高频振铃,引发EMI问题。串联小电阻(Rboot)可引入阻尼效应,抑制振铃、改善波形和EMI性能,但会略微增加开关损耗。设计时建议预留可调电阻位(2Ω~20Ω),根据实测结果平衡效率与系统稳定性,提升电源可靠性。这一措施是优化开关电源EMC的常见实践。

硬核科技 625

UVa 623 500!

本文介绍了如何计算大整数阶乘的高精度算法。由于内置数据类型无法存储如1000!这样的大数,需采用高精度计算方法。文章提出使用万进制(基数为10000)的大整数实现,通过数组存储数位,每组四位十进制数。解题思路包括:设计支持大整数运算的类,预计算0!到1000!的阶乘并存储,最后直接查询输出。该方法的时间复杂度约为O(2.5×10^6)次操作,空间复杂度约2.5MB,能够高效处理输入规模。

寂静山林 285

STM32+CubeMX实战:5步搞定LWIP HTTP服务器搭建(附常见编译错误解决)

本文详细介绍了基于STM32和CubeMX平台,快速搭建LWIP HTTP服务器的5步实战指南。内容涵盖从项目初始化、LWIP深度配置到解决经典的`HTTPD_FSDATA_FILE`编译错误,并分享了使用VSCode进行高效开发的工作流,旨在帮助嵌入式开发者快速实现网络功能并规避常见陷阱。

weixin_29192365的博客 573

Android14_MTK调试LCD屏功能

android14 MTK平台调试LCD屏

m0_37786046的博客 1472

UVa 623 - 500!

题目:大整数阶乘计算。 分析:简单题、模拟。大数计算,可以采用位数压缩,节约时间空间。把k位存入一位,每次10^k进位即可,利用%0kd输出很方便。 注意:500!有2632位,位数开少会WA。 #include #include #include int ans[ 451 ]; int main() { int N; while ( scanf("%d",&N) != E

小白菜又菜 1108

计组实验之四路表决器

请在之前四路表决器电路实现的基础上,继续用连接线 联接CD4511,将投票为1的票数总和显示到一个 LED上,思考如何做?由于我们需要通过显示字形来直接看出有几个1,在这里,我们最多有四个1,即显示字形最多到4就行,所以我们需要将有几个1用2进制数来表示,下面给出了相关电路图。显示输入插口,按真值表(自拟)要求,逐次改变输入变量, 测量相应的输出值,验证逻辑功能, 与表3-1 进行比较, 验证所设计的逻辑电路是否符合要求。用实验结果与真值表3-1和3-2进行比对,可以得出,我们实验结果是正确的。

szyugly的博客 1万+

uva 623 - 500!

求阶乘。 最多1000; 必须先把每个阶乘用字符串存好,要不然会超时。。 用高精度乘法从一开始算出每个值。然后询问直接输出 #include #include #include using namespace std; const int MAXN=3000; const int M=1000+10; string sol[M]; char fact[MAXN]; int len; voi

catfish的专栏 1342

OpenCV实例(一)人脸检测

计算机视觉使很多任务成为现实,其中两项任务就是人脸检测(在图像中定位人脸)和人脸识别(将人脸识别为特定的人)。OpenCV实现了一些人脸检测和识别的算法。从安全到娱乐,这些技术在现实环境中都有应用。介绍OpenCV的一些人脸检测和识别功能,并定义特定类型的可跟踪物体的数据文件。具体来说,将研究Haar级联分类器,通过分析相邻图像区域之间的对比度,确定给定图像或子图像是否与已知类型匹配。

小幽余生不加糖 5004

STM32G4 电机外设篇(三) TIM1 发波 和 ADC COMP DAC级联

STM32G4电机控制外设应用笔记摘要:本文详细介绍了TIM1高级定时器生成三对互补PWM波的配置方法(预分频器PSC=30000,重装载值ARR=10000),重点说明需断开电机连线避免干扰。通过STM32CubeMX配置TIM1通道4触发ADC采样,设置RCR分频参数,并给出Keil代码修改要点。第二部分探讨了TIM1、ADC、比较器和DAC的级联应用,包括电流采样触发时序(在PWM波峰值前采样)和过流保护机制。配置步骤包含DAC3作为比较器负输入端、设置Break触发封波保护,并附关键代码段实现外设联

qq_43091070的博客 1101

UVa 623 500! (高精度阶乘)

623 - 500! Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=564 In these days you can more and more often hap

AC,∑ndless 1264

ABAP 7.40 新语法介绍系列之二 - ABAP 类型转换操作符 CONV

这个lv_input_s变量的唯一使命,就是接收来自 char10 类型的 lv_input_c 变量的值,然后传递到 print 方法里去。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1417

UVA623-500!(模拟乘法 or BigInteger)

题目链接 In these days you can more and more often happen to see programs which perform some useful calculations being executed rather then trivial screen savers. Some of them check the system message qu...

QAQ 249

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

UVA623 500!【百万进制/10^15进制】

In these days you can more and more often happen to see programs which perform some useful calculations being executed rather then trivial screen savers. Some of them check the system message queue an...

海岛Blog 756

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

[Uva623]500!(高精)

Description 求N! \(N \leq 1000\) Sample Input 10 30 50 100 Sample Output 10! 3628800 30! 265252859812191058636308480000000 50! 30414093201713378043612608166064768844377641568960512000000000000 100! 933...

weixin_34194317的博客 141

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

UVa OJ 623 阶乘

UVa OJ 623  lem C

黄金之心 626

《算法竞赛入门经典》中例题对应题目

目前只找到一部分uva上的题目,其它的应该是没有了,或者我还没找到... 注:带有“类似”标记的题目表明为类似的题目,可能与例题有些出入,但不是很大,用的是同样的方法。 第五章: 5.1.1 WERTYU UVa10082 - WERTYU 5.1.2 TEX括号 UVa272 - TEX Quotes 5.1.3 周期串 UVa455...

weixin_34265814的博客 165

π-Algorithmist分类题目(3)

原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Pageπ-Algorithmist分类题目(3)Probability TheoryUVA 10288 CouponsUVA 10491 Cows and CarsUVA 10900 So you want to be a 2n-aire?Numerical MethodUV...

海岛Blog 933

一些蒟蒻认为的好题(趣题)【更新中】

Question 1来源:uva1657Description很久很久以前有鬼谷先生,他有两位弟子,一位叫孙膑,另一位叫庞涓,一天鬼谷子想考一考他的两个徒弟,他在心中想了两个正整数,我们用x和y代替,其中1≤x<y≤n1 \le x \lt y \le n,然后鬼谷先生公布了这个n,接着它将两个数的和告诉了孙膑,将两个数的积告诉了庞涓,然后依次循环询问孙膑庞涓两人是否知道这两个数是多少,(总是先问孙

gankinghand的博客 538

UVA 122 - Trees on the level

Background Trees are fundamental in many branches of computer science. Current state-of-the art parallel computers such as Thinking Machines' CM-5 are based on fat trees. Quad- and octal-trees are

2271

UVA 536 - Tree Recovery

Little Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital letters in the nodes. This is an example of one of her creati

1861

UVA 725 - Division

Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divided by the second is equal to an integer N

1860
上一篇: UVA 623 - 500!
下一篇: java.lang.RuntimeException: Stub!
chiiis
博客等级 码龄14年 422粉丝 429原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值