POJ 2661-factstone Benchmark (Application of log ())

Source: Internet
Author: User
Tags benchmark

Title Address: POJ 2661
Test instructions: Starting from 1960, the maximum number of storage bits of the computer is updated every 10 years, with the first 1960-year word length being 4 bits, and the subsequent growth of one-fold every 10 years. Give you a year, ask this year, the computer can execute n! The maximum n value without overflow.
Idea: The number of digits in the nth year k=2^ (y-1960)/10, the largest unsigned integer that can be placed in K-bit is (2^k)-1 if it is directly not greater than (2^k)-1 n! is easy to overflow and slow, we introduce a logarithmic operation that is based on log2 (n! ) =log2 (1) +.....+log2 (n) <=log2 ((2^k)-1)

#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>#pragma COMMENT (linker, "/stack:102400000,102400000")using namespace STD;typedef Long LongLL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-7;intMain () {intNDoubleK,sum; while(~scanf("%d", &n)) {if(!n) Break; k=Log(4*1.0); for(intI=1960; i<=n;i+=Ten) k*=2; sum=0;intCnt=1; while(sum<k)        {++cnt; sum+=Log((Double) (CNT)); }printf("%d\n", cnt-1); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 2661-factstone Benchmark (Application of log ())

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.