Factorial vs Power log数学题

原题Factorial vs Power

题意

找到最小的n使得n!>a^n

解析

两边同时取log,得log(1)+…log(n)>n*log(a)

用L数组存一下log的前缀和,二分找ans

代码

#include<cstdio>
#include<cmath>
#define F double
#define N (int)(1e7+10.0)

F L[N];
int main(){
    L[0]=0;for(int i=1;i<N-10;i++)L[i]=L[i-1]+log(i);
    int t;scanf("%d",&t);while(t--){
        int a;scanf("%d",&a);
        F b=log(a);
        int l=1,r=1e7;
        while(r-l>1){
            int mid=r+l>>1;
            if(L[mid]>mid*b)r=mid;
            else l=mid;
        }
        printf("%d\n",l+1);
    }
}
阅读更多

扫码向博主提问

jk_chen_acmer

非学,无以致疑;非问,无以广识
去开通我的Chat快问

Factorial

02-14

DescriptionnnThe most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to the BTS with the strongest signal (in a little simplified view). Of course, BTSes need some attention and technicians need to check their function periodically. nnACM technicians faced a very interesting problem recently. Given a set of BTSes to visit, they needed to find the shortest path to visit all of the given points and return back to the central company building. Programmers have spent several months studying this problem but with no results. They were unable to find the solution fast enough. After a long time, one of the programmers found this problem in a conference article. Unfortunately, he found that the problem is so called "Travelling Salesman Problem" and it is very hard to solve. If we have N BTSes to be visited, we can visit them in any order, giving us N! possibilities to examine. The function expressing that number is called factorial and can be computed as a product 1.2.3.4....N. The number is very high even for a relatively small N. nnThe programmers understood they had no chance to solve the problem. But because they have already received the research grant from the government, they needed to continue with their studies and produce at least some results. So they started to study behaviour of the factorial function. nnFor example, they defined the function Z. For any positive integer N, Z(N) is the number of zeros at the end of the decimal form of number N!. They noticed that this function never decreases. If we have two numbers N1 < N2, then Z(N1) <= Z(N2). It is because we can never "lose" any trailing zero by multiplying by any positive number. We can only get new and new zeros. The function Z is very interesting, so we need a computer program that can determine its value efficiently. nnInputnnThere is a single positive integer T on the first line of input. It stands for the number of numbers to follow. Then there is T lines, each containing exactly one positive integer number N, 1 <= N <= 1000000000.nOutputnnFor every number N, output a single line containing the single non-negative integer Z(N).nSample Inputnn6n3n60n100n1024n23456n8735373nSample Outputnn0n14n24n253n5861n2183837

没有更多推荐了,返回首页