Big Number(log10求位数)
来源:互联网 发布:托管淘宝店铺 编辑:程序博客网 时间:2024/06/05 17:19
The output contains the number of digits in the factorial of the integers appearing in the input.
21020
719
题意:
就是让你求n!有几位,如果普通的求法,会爆!!
思路:
运用log10求位数!!
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <string>#include <map>#include <stack>#include <vector>#include <set>#include <queue>#define maxn 15#define MAXN 100000005#define mod 7#define INF 0x3f3f3f3f#define exp 1e-6#define pi acos(-1.0)using namespace std;int main(){ //freopen("D:\\a.txt","r",stdin); int n,i,t; ios::sync_with_stdio(false); double sum; cin>>t; while(t--) { sum=0; cin>>n; for(i=1;i<=n;i++) sum=sum+log10(i); cout<<(int)sum+1<<endl; } return 0;}
此题和寒假集训时做过的一个题一摸一样!!附上:
Description
元宵节到了,Snow也准备一掷千金买汤圆来庆祝元宵节。Snow非常慷慨,他将分享给你一定数量的汤圆,那么是多少个汤圆呢?答案是 n!(n的阶乘)……嘻嘻别傻了,Snow要分享给你的是 n!的位数个汤圆,但前提是你得求出 n!有多少位哦。
Input
输入数据有多组(数据组数不超过 500),到EOF 结束。
每组数据输入 n (1 <= n <= 500)。
Output
对于每组数据,输出一行,表示 n!的位数。
Sample Input
1
20
Sample Output
1
19
Hint
#include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
int i,x,j,a[9999]={0},b[9999]={0},len=0;
//定义数组存放大数,a为暂时存放数值
a[1]=b[1]=1;
a[0]=b[0]=1;
for(i=1;i<=n;i++)
{
x=0;
len+=4;//len为位数,因为n最大为500,所以len每次最大加4位
for(j=1;j<=len;j++)
{
b[j]=a[j]*i+x;
x=b[j]/10;
b[j]%=10;
}
while(b[len]==0&&len>1)
len--;
//删除前导0,使位数正好
for(j=1;j<=len;j++)
a[j]=b[j];
}
cout<<len<<endl;
}
return 0;
}
#include<iostream>
#include<cstring>
using namespace std;
int a[100000],n,i,y,xy[100000];
int main()
{
cin>>n;
a[0]=1;
a[1]=1;
for (y=1;y<=n;y++)
{
memset(xy,0,sizeof(xy));
xy[0]=a[0];
for (i=1;i<=a[0];i++)
{
xy[i]+=a[i]*y;
xy[i+1]=xy[i]/10;
xy[i]%=10;
}
while (xy[xy[0]+1]>0)
{
xy[xy[0]+2]=xy[xy[0]+1]/10;
xy[xy[0]+1]%=10;
xy[0]++;
}
for (i=1;i<=xy[0];i++) a[i]=xy[i];
a[0]=xy[0];
}
for (i=a[0];i>=1;i--) cout<<a[i];
cout<<endl;
cout<<a[0] ;
cout<<endl;
return 0;
}
f题考察高精度计算
#include<algorithm>
#include<string>
#include<cmath>
using#include<iostream>
namespace std;
int main()
{
int n,i,j,k;
double sum;
while(cin>>n)
{
for(i=1;i<=n ;i++)
{
sum=sum+log10(i);
}
cout<<(int)sum+1<<endl;
}
return 0;
}
- Big Number(log10求位数)
- HDU 1018 Big Number(求n!的位数)
- Big Number(hdu1018,求n!的位数)
- HDU 1018 Big Number(求n!的位数)
- 求大数阶乘的位数(ACM Big Number问题)
- hdu 1018 big number (求N!的位数)
- Big Number(求阶乘数的位数)
- hdu 1018 Big Number(公式求阶乘位数)
- Big Number(求任意阶乘的位数)
- HDU1018 Big Number(求阶乘位数)
- UVa1185 - Big Number(求阶乘的位数)
- 【HDU1018】Big Number - 求n!的位数
- 求位数 hdu 1018 Big Number
- HDOJ 1018 Big Number (对数求位数)
- poj 1423 Big Number<<求N!位数>>
- hdu-1018Big Number(阶乘求位数)
- hd 1018 Big Number 正整数a的位数(int)log10(a)+1;n的阶乘的位数
- hdu 1018 Big Number (求一个数的阶乘的位数,公式!!!)
- 设置diaog.builder的透明度
- Dom4j设置编码的问题(转载)
- ubuntu下Octomap如何安装 ubuntu14.04下如何安装libqglviewer
- php环境搭建(3)----useradd
- 【算法题】
- Big Number(log10求位数)
- JS创建对象的几种方法
- 使用Python向Excel中插入图片
- 从界面获取bean的id时注意
- HDU
- java的各种集合使用
- PHP环境搭建(4)----安装php
- ssh:connect to host localhost port 22: Connection refused解决方法
- Java的重载和重写区别