杭电OJ题1018 Big Number 解题报告

本文介绍了一个计算大整数阶乘位数的方法,使用log10()函数逐个累加输入整数范围内每个数的对数值,进而得出阶乘结果的位数。
部署运行你感兴趣的模型镜像

Big Number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18173    Accepted Submission(s): 8167


Problem Description
In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of digits in the factorial of the number.
 

Input
Input consists of several lines of integer numbers. The first line contains an integer n, which is the number of cases to be tested, followed by n lines, one integer 1 ≤ n ≤ 10 7 on each line.
 

Output
The output contains the number of digits in the factorial of the integers appearing in the input.
 

Sample Input
  
2 10 20
 

Sample Output
  
7 19
 

Source
 

Recommend
JGShining
 

————————————————————————————————————————
通过log10()来处理


/****************************
 *Name:Big Number.c
 *Tags:ACM Math
 *Note:通过log10()来处理
 ****************************/

#include <stdio.h>
#include <math.h>

int main()
{
      int N, num;
      double sum, i;
      scanf("%d", &N);
      while(N--) {
	    scanf("%d", &num);
	    sum = 0;
	    for(i = 1; i <= num; i++) {
		  sum += log10(i);
	    }
	    printf("%d\n", (int)(sum)+1);
      }
      return 0;
}


您可能感兴趣的与本文相关的镜像

Dify

Dify

AI应用
Agent编排

Dify 是一款开源的大语言模型(LLM)应用开发平台,它结合了 后端即服务(Backend as a Service) 和LLMOps 的理念,让开发者能快速、高效地构建和部署生产级的生成式AI应用。 它提供了包含模型兼容支持、Prompt 编排界面、RAG 引擎、Agent 框架、工作流编排等核心技术栈,并且提供了易用的界面和API,让技术和非技术人员都能参与到AI应用的开发过程中

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值