SOJ 1119. Factstone Benchmark

Source: Internet
Author: User
Tags benchmark

Title: Given y, the maximum value of K ((y-1960)/10+2) > k! is satisfied.

Problem-solving ideas: Through the two sides at the same time to the logarithm, to achieve the effect of power, so that the number of both sides can be stored with their own type.
After taking the logarithm: 2 ((y-1960)/10+2) * Log (2) > Log (k!).

Further conversions: 2 ((y-1960)/10+2) > log (k!)/log (2) = log (k)/log (2) + log (k-1)/log (2) + log (k-2)/log (2) + ... +log (1)/log (2).

Due to Y <= 2160, the desired (y-1960)/10+2 <= 22, so the Left 2 ((y-1960)/10+2) <=222. In the self-contained type bearing.

The final traverse to solve K can

The code is as follows:

1#include <cstdio>2#include <cmath>3 4 5 //Reference:http://www.lxway.com/18542861.htm6 7 //2^ (2^ ((y-1960)/10+2) > k!8 //2^ ((y-1960)/10+2) * Log (2) > log (k!) = log (k) + log (k-1) + log (k-2) + ... + log (1)9 intBenchmarkinty) {Ten     intE = (Y-1960) /Ten+2; One     intleft =1<<e; A     intK =0; -     Doubleres =0; -      while(Left >Res) { theRes + = log (++k)/log (2); -     } -     return--K; - } +  - intMain () { +     inty; A      while(SCANF ("%d", &y) { at         intK =benchmark (y); -printf"%d\n", k); -     } -     return 0; -}

Reference:

Sicily 1190. Factstone Benchmark

SOJ 1119. Factstone Benchmark

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.