题解:UVA10916 Factstone Benchmark

· · 题解

题意概括

在 1960 年有四比特的计算机,1970 年有八比特的计算机,第 X 年有 2^{2 \times \lfloor \frac{x-1940}{10} \rfloor } 比特的计算机。

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

思路分析

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

\begin{aligned} N! \le 2^{2 \times \lfloor \frac{x-1940}{10} \rfloor } \end{aligned}

两边同时取对数,可得:

\begin{aligned} \log_{2}{N!} \le 2 \times \lfloor \frac{x-1940}{10} \rfloor \end{aligned}

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

\begin{aligned} \sum_{i=1}^{N} \log_{2}{i} \le 2 \times \lfloor \frac{x-1940}{10} \rfloor \end{aligned}

令 2 \times \lfloor \frac{x-1940}{10} \rfloor 为 A。

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

代码解析

#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;
}

提交记录