跳到正文

题解

题解:UVA10916 Factstone Benchmark

sjh0626约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年1月16日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 2 分钟
题目
UVA10916

版本

  1. v1当前

题意概括

在 19601960 年有四比特的计算机,19701970 年有八比特的计算机,第 XX 年有 22×⌊x−194010⌋2^{2 \times \lfloor \frac{x-1940}{10} \rfloor } 比特的计算机。

请你求出一个最大的 NN 使得 N!N! 在二进制中可以被第 XX 年的计算机表示。

思路分析

这其实就是一道数学题,首先有一个方程:

N!≤22×⌊x−194010⌋\begin{aligned} N! \le 2^{2 \times \lfloor \frac{x-1940}{10} \rfloor } \end{aligned}

两边同时取对数,可得:

log⁡2N!≤2×⌊x−194010⌋\begin{aligned} \log_{2}{N!} \le 2 \times \lfloor \frac{x-1940}{10} \rfloor \end{aligned}

因为 log⁡cXY=log⁡cX+log⁡cY\log_{c}{XY} = \log_{c}{X} + \log_{c}{Y},所以化简可得。

∑i=1Nlog⁡2i≤2×⌊x−194010⌋\begin{aligned} \sum_{i=1}^{N} \log_{2}{i} \le 2 \times \lfloor \frac{x-1940}{10} \rfloor \end{aligned}

令 2×⌊x−194010⌋2 \times \lfloor \frac{x-1940}{10} \rfloor 为 AA。

而我们可以枚举 ii,一直对 AA 一直减 log⁡2i\log_{2}{i},直到 A<0A < 0 为止。

代码解析

C++
#include<bits/stdc++.h>
#define sjh0626s return
#define code 0
#define ll long long
#define PII pair<int,int>
using namespace std;
int x,now,sum;
double maxx;
int main(){
	cin>>x;
	while(x!=0){
		maxx=pow(2,((x-1940)/10));
		now=0;
		while(maxx>=0){
			maxx-=log2(++now);
		}
		cout<<now-1<<"\n";
		cin>>x;
	}
	sjh0626s code;
}

提交记录

原文