Bzoj 1192 The money bag of the ghost millet

Source: Internet
Author: User

The topics are as followsDescription

Ghost Millet is very clever, because of this, he is very busy, often have the Commissioner of the car's special agent came to him to consult politics. One day, when he traveled in Xianyang, his friend told him that the largest auction house in Xianyang (Ju Bao) is going to hold an auction, in which one of the treasures aroused his great interest, that is no word heavenly book. However, his itinerary is very full, he has bought a long-distance coach to Handan, unfortunately, the departure time is at the end of the auction. So, he decided to prepare in advance, the number of his own gold and a small bag good, so that in his existing gold coins under the ability to pay, any number of gold coins he can use these closed a combination of good money for the bill. Ghost Valley is also a very frugal person, he tried to make himself in the premise of satisfying the above requirements, the use of the minimum number of bags, and no two money bags have the same number of gold more than 1. Suppose he had m gold coins, could you guess how many money bags he would use, and how many gold coins were in each bag?

Input

Contains an integer that represents the total number of gold coins existing in the ghost millet m. Among them, 1≤m≤1000000000.

Output

Only an integer h, indicating the number of pockets of money

Sample Input

3

Sample Output

2

According to the previous experience of doing the problem, we should look at the data range and 1≤m≤1000000000. The average time complexity for such a large data is the log level. So I think in this respect. Thought of a previous theorem:

1+21+22+23+...+2k-1=2k-1

and all integers from 1 to 2k-1 can be represented by a few of the top ones. And with the multiplication, this is not the algorithm that fits the log level. Just start with now=1, let the Money (m) minus now, then multiply it, and the loop boundary is m<=0. The code is short:

#include <iostream>
#include
<cstdio> using namespace std; int m,t,now=1 ; int Main () {scanf ("%d",& m); while (m>0 ) {m-=Now ; t+ + ;now *=2 ;} cout<<
t;}

Bzoj 1192 The money bag of the ghost millet

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.