UVA - 10916 Factstone Benchmark
来源:互联网 发布:广州新科佳都科技 知乎 编辑:程序博客网 时间:2024/06/05 16:15
题目大意:从 1960 年开始,每十年位数翻一倍,最开始是 4bit,求最大的 n 使得 n!小于当前电脑位数所能表示的最大无符号整数。如 1960 年 4bit,所能表示的最大整数为 2^4=16。
1!=1,2!=2,3!=6,4!=24。
当 n=4,n! 大于 15,所以 n=3。
解题思路:根据题意即求 1×2×3×4×…×n < 2^bit,显然直接去求会溢出。两边取对数去求。
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>using namespace std;int main() { int y, n; while(scanf("%d", &y) != EOF && y) { int bit = pow(2,((y - 1960) / 10 + 2)); double sum = 0; for (int i = 2; ; i++) { sum += log(i)/log(2); if (bit < sum) { n = i-1; break; } } printf("%d\n", n); } return 0;}
0 0
- UVa 10916 Factstone Benchmark
- uva 10916 Factstone Benchmark
- UVA 10916 - Factstone Benchmark
- UVa 10916 - Factstone Benchmark
- uva 10916 - Factstone Benchmark
- uva-10916 - Factstone Benchmark
- Uva 10916 - Factstone Benchmark
- uva 10916 - Factstone Benchmark
- UVa 10916 - Factstone Benchmark
- UVA 10916 Factstone Benchmark
- uva 10916 Factstone Benchmark
- UVa 10916 Factstone Benchmark
- UVa 10916 - Factstone Benchmark
- UVa 10916 - Factstone Benchmark
- UVa 10916 - Factstone Benchmark
- UVa 10916 - Factstone Benchmark
- UVA 10916 Factstone Benchmark
- UVA - 10916 Factstone Benchmark
- android动画定义
- 从 ASP .NET 进行 Active Directory 域服务身份验证
- java-jni-01-Introduction
- HDU4069(未AC)
- STM32F1学习-时钟系统
- UVA - 10916 Factstone Benchmark
- HDOJ 5499 SDOI(典型的翻译题目,处理女生特殊情况的问题)
- 嵌入式c语言 之数据结构:为什么嵌入式要选择c语言? *c的可移植性好:能在不同平台的结构访问硬件 *c具有简洁紧、使用灵活的语法机制,并能直接访问硬件。 *c具有高效的运行效率
- centos 6.4 安装oracle 11.2.0.3 grid报错
- SAP BDC
- 【CDP-云设计模式】第4章,7.改写代理模式(Rewrite Proxy Pattern)
- c语言的100个经典算法
- HDU 1271 整数对
- 游戏编程中的人工智能技术-神经网络入门(三)