题意概括
在 1960 年有四比特的计算机,1970 年有八比特的计算机,第 X 年有 22×⌊10x−1940⌋ 比特的计算机。
请你求出一个最大的 N 使得 N! 在二进制中可以被第 X 年的计算机表示。
思路分析
这其实就是一道数学题,首先有一个方程:
N!≤22×⌊10x−1940⌋
两边同时取对数,可得:
log2N!≤2×⌊10x−1940⌋
因为 logcXY=logcX+logcY,所以化简可得。
i=1∑Nlog2i≤2×⌊10x−1940⌋
令 2×⌊10x−1940⌋ 为 A。
而我们可以枚举 i,一直对 A 一直减 log2i,直到 A<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;
}
提交记录