ECNU_OJ_1007
来源:互联网 发布:特斯拉和比亚迪 知乎 编辑:程序博客网 时间:2024/06/06 04:39
N!的最高位
Time Limit:1000MS Memory Limit:30000KB
Total Submit:2241 Accepted:365
Description
求N的阶乘的最高位数。
例如:
5!=120,所以最高位为1
10!=3628800,所以最高位为3
Input
每个数据包含一行,每行有一个整数N(0<=N<=10000000)
Output
对于每个测试数据,输出N!的最高位数字
Sample Input
5
10
Sample Output
1
3
Source
EOJ
#include <stdio.h>#include <math.h>//stirling公式#define pi 3.1415926535898#define e 2.718281828459int main(int argc, char** argv){ int n; while(scanf("%d", &n) != EOF) { double temp; temp = (0.5 *log(2*pi*n) + n*(log(n) - log(e))) / log(10.0); temp -= (int)temp ; temp = exp(temp * log(10.0)); switch(n) { case 0: case 1: printf("1\n"); break; case 2: printf("2\n"); break; case 3: printf("6\n"); break; case 7: printf("5\n"); break; case 8: printf("4\n"); break; default: printf("%d\n",(int)temp); break; } } return 1;}
0 0
- ECNU_OJ_1007
- spring 读取配置文件源码解析
- 设计模式(四)--建造者模式
- 关于程序设计原则的一些思考
- 使用checkinstall1.6.1时遇到的问题
- hdu 【1011】Starship Troopers
- ECNU_OJ_1007
- 使用Fiddler对手机应用进行抓包测试 (试了一下, 靠谱)
- 错误信息收集
- 【Vuforia】基于Vuforia增强现实开发(一)之识别图像播放声音
- JavaScript 原型模式的理解
- Android 多线程文件断点下载器实现(造轮子系列)(二)
- python爬取某个贴吧帖子留下的邮箱,并自动发送相应链接
- LeetCode题解--8. String to Integer (atoi)
- Python multiprocessing threading