zoukankan      html  css  js  c++  java
  • poj2661Factstone Benchmark

    链接

    利用log函数来求解 n!<=2^k k会达到400+W 暴力就不要想了,不过可以利用log函数来做

    log2(n!) = log2(1)+log2(2)+..log2(n)<=k

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<stdlib.h>
     6 #include<vector>
     7 #include<cmath>
     8 #include<queue>
     9 #include<set>
    10 #include<map>
    11 using namespace std;
    12 #define N 100000
    13 #define LL long long
    14 #define INF 0xfffffff
    15 const double eps = 1e-8;
    16 const double pi = acos(-1.0);
    17 const double inf = ~0u>>2;
    18 int main()
    19 {
    20     int i,j,n;
    21     //cout<<log10(10)<<" "<<log(10)<<endl;
    22     while(cin>>n)
    23     {
    24         if(!n) break;
    25         LL k = 2;
    26         for(i = 1960 ; i <= n ; i+=10)
    27         k*=2;
    28         double d=0;
    29         int ans;
    30         for(i = 1; ; i++)
    31         {
    32             d+=log10(i*1.0)/log10(2.0);
    33             if(d>k)
    34             {
    35                 ans = i-1;
    36                 break;
    37             }
    38         }
    39         cout<<ans<<endl;
    40     }
    41     return 0;
    42 }
    View Code
  • 相关阅读:
    py 5.11
    py 5.10
    py 5.9
    py 5.8
    python 5.7
    python 5.4
    python 5.3
    python 5.2
    python 4.28
    python 4.27
  • 原文地址:https://www.cnblogs.com/shangyu/p/3620005.html
Copyright © 2011-2022 走看看