HPU 1042 counterfeit currency problem

1042: Counterfeit Currency Problem  [Thinking]

Time Limit: 1 Sec   Memory Limit: 128 MB

Commits: 200   Resolved: 34   Stats

Topic description

There are fake coins! ! !

Here's the thing, now that pork has risen, but farmers' wages haven't risen, so how can they buy pork without money. Lao Wang went to buy pork, but the change he found contained counterfeit money! ! ! It's a pity that Lao Wang accidentally mixed it into a pile of real coins. It is now known that counterfeit coins weigh less than genuine coins. Give you a scale, please use the fastest time to find out that hateful counterfeit coin.

enter

Enter multiple lines.

The value of each row is the number of coins nn,1n2301≤n≤230

Enter 0 to end the program.

output

It takes at least how many times to weigh to find the counterfeit coin.

The output corresponds to the number of input lines.

sample input

3
12
0
 
 

Sample output

1

3

...

find rules

AC

#include<iostream>  
#include<cmath>  
using namespace std;
int main()  
{  
    long long n,a;  
    while(cin>>n && n!=0)  
    {  
        if(n==1)   
          a=0;  
        else  
          a=log(n-1)/log(3)+1;  
        cout<<a<<endl;  
    }  
    return 0;  
}  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324601800&siteId=291194637