K-Big Number

学习了斯特林公式,对n的阶乘有简化的运算,之后用log10取位数
#include <iostream>
#include <cmath>
using namespace std;
const long double a=0.79817986835811504;//lg(2*pi)
const long double b=0.434294481903;//lg(e)
//斯特林公式 lg(n!)=(lg(2*pi)+lg(n))/2 + n*(lg(n)-lg(e))
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,p;
		cin>>n;
		long double c=log10((double)n);
		if(n>3)p=(a+c)/2+n*(c-b)+1;
		else p=1;
		cout<<p<<endl;
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码已经是一个标准的算法伪代码了,它使用了algorithmic宏包提供的`algorithmic`环境来输入。其中,`\REQUIRE`和`\ENSURE`命令用来设置输入和输出,`\STATE`命令用来输入每一行的语句。此外,这个算法伪代码还使用了`\IF`、`\FOR`、`\WHILE`等命令来描述算法的流程。最后,`\RETURN`命令用来输出结果。 如果你想要使用algorithm2e宏包来输入这段代码,可以参考下面的示例: ``` \usepackage[lined,boxed,commentsnumbered,ruled,linesnumbered]{algorithm2e} \begin{algorithm}[H] \SetAlgoLined \caption{FRRSC} \label{alg:frrsc} \SetKwInOut{Input}{Input} \SetKwInOut{Output}{Output} \Input{N is big dataset. m samples in each group. b and b' set by us due to the data type and demand of user as standards of similarity. The samples T[1] to T[i-1] and each set is with m indexes from T[a,1] to T[a,m](1<=a<=i-1)} \Output{The group of indexes from T[1] to T[n]} $p\gets i\times x$\; number $i\times m+1$ to N tuples from 1 to N-i\times m\; \While{($k<m$ and $i<|N|$)}{ \If{$N_i$ is complete}{ $S_k\gets N_i$\; $k\gets k+1$\; } $i\gets i+1$\; } \While{$i<|N|$}{ \If{$N[t]$ is complete}{ \For{$j=0$ to $m-1$}{ \If{cmp($N_i,S_j$)$\geq \epsilon$}{ $q\gets q+1; k\gets$ rand[1,$q$]\; } \If{$k\leq m$}{ $S_j \gets N_i$\; break\; } } } $i \gets i+1$\; } \Return $S$\; \end{algorithm} ``` 在这个例子中,我们使用algorithm2e宏包来输入算法伪代码。`\SetAlgoLined`命令可以设置代码的格式,`\SetKwInOut`命令用来设置输入和输出。此外,我们还对代码进行了一些调整,比如将注释用`\;`来标记,去掉了一些多余的空格。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值