N的阶乘的长度(斯特林)
来源:互联网 发布:上海网页美工培训班 编辑:程序博客网 时间:2024/04/30 11:36
题目传送门: https://www.51nod.com/onlineJudge/submitList.html#!userId=11254&problemId=1130
给一个数N,求出N的阶乘的长度
一、取对数的做法
用对数的性质,将若干个数相乘改为若干对数相加的形式O(n)的时间复杂度
代码如下:
#include <iostream>#include <algorithm>#include <cstring>#include <stdio.h>#include <string>#include <cmath>#define ll long long#define mem(name,value) memset(name,value,sizeof(name))using namespace std;const int maxn = 1000005;const int _max = 1000000;int a[maxn];int main(){ double n; cin >> n; double cnt = 0; for(double i=1;i<=n;i++){ cnt += log10(i); } cout << (int)cnt + 1 <<endl; return 0;}
二、斯特林公式
ans = 0.5 * log10(2.0 * PI * n) + n * log10(n * 1.0 / E) + 1;
o(1)的时间复杂度
代码如下:
#include <iostream>#include <algorithm>#include <cstring>#include <stdio.h>#include <string>#include <cmath>#define ll long long#define mem(name,value) memset(name,value,sizeof(name))#define mod 1000000007#define PI 3.1415926#define E 2.718281828459using namespace std;const int maxn = 1005;double getlg(double x){ double cnt = 0; while(x > 10){ x /= 10; cnt++; } x += cnt; return x;}int main() { int t; cin >> t; for(int i=0;i<t;i++){ int n; cin >> n; ll res = 0.5 * log10(2.0 * PI * n) + n * log10(n * 1.0 / E) + 1; cout << res << endl; } return 0;}
0 0
- N的阶乘的长度(斯特林)
- n的阶乘长度(斯特林公式)
- N的阶乘的长度 斯特林近似
- 斯特林近似求N阶乘的长度
- N的阶乘的长度(斯特林公式)
- 1130 N的阶乘的长度 V2(斯特林近似)
- 1130 N的阶乘的长度 V2(斯特林近似)
- 1130 N的阶乘的长度 V2(斯特林近似)
- 51Nod 1058 N的阶乘的长度(斯特林)
- 1130 N的阶乘的长度 V2(斯特林近似)
- n的阶乘的长度
- 求N阶乘的长度
- 51nod 1130 N的阶乘的长度(阶乘近似公式--斯特林公式)
- 51Nod关于n的阶乘的长度(斯特林公式近似计算阶乘)
- 51NOD 求n的阶乘的长度(斯特林公式)
- 求n的阶乘的长度 斯特林共识
- N的阶乘的长度V2 【斯特林公式】
- 51nod_1058 N的阶乘的长度(斯特林公式)
- Rsync
- Use snippets in vim
- React-Native初体验一(window环境下开发)
- 华信9月11日上课心得
- 使用FireFox插件RESTClient、HttpRequester模拟http(get post)请求
- N的阶乘的长度(斯特林)
- Linux下的V4L2的API编程总结
- 个人网站配置HTTPS
- MySql5.7 zip windows安装教程
- spring boot 学习笔记(005)提交json对象
- SQL的四种连接-左外连接、右外连接、内连接、全连接
- 伪静态动态参数URL重定向到原URL
- 8. 练习:创建一个Eclipse plug-in项目
- 嵌入式软件笔试题