首页 > 其他 > 详细

Suneast & Daxia (规律)

时间:2014-03-11 14:33:21      阅读:497      评论:0      收藏:0      [点我收藏+]
Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u

[]   [Go Back]   [Status]  

Description

Daxia is so cute that people loves it so much.

Everyone wants to buy Daxia from Suneast (a business man who sells Daxia).

 

bubuko.com,布布扣

 

Suneast is a strange business man. He sells Daxia in a random price from 1, 2, 3, 4, 5…, n.

We now consider the price of Daxia is N $. If a custom has M $(M>=N) in hand and buy Daxia using Q $(N<=Q<=M), Suneast needs to return R=(Q-N) $ to the custom. Suneast is so a strange business man that he take the Q $, and he refuses to look for a change if the custom can’t show him R$ in his hand.

Now, we want to know how many pieces of money people should bring with to buy a Daxia with the exactly price. (The value of money can be any positive integers.)

Input

There are multiple test cases. Each test case has an integer n (1<=n<=254664467) in a single line.

Output

For each case, output a single integer in a line indicates the number of pieces of money people should bring with to buy a Daxia whose price is random from 1 to n.

Sample Input

1
2
5

Sample Output

1
2
3

Hint

In test case 1: people can bring 1 piece of money: 1$

In test case 2: people can bring 2 pieces of money:

bubuko.com,布布扣

In test case 3: people can bring 3 pieces of money:

bubuko.com,布布扣
呵呵,这题看师兄的才懂了!
 
bubuko.com,布布扣
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <math.h>
 4 #include <string.h>
 5 #include <algorithm>
 6 using namespace std;
 7 int main()
 8 {
 9     int n;
10     long long  a[50];
11     a[0]=0;
12     for(int i=1;i<50;i++)a[i]=a[i-1]*3+1;
13     while(cin>>n)
14     {
15         for(int i=0;i<50;i++)
16         if(n<=a[i])
17         {
18             cout<<i<<endl;
19             break;
20         }
21     }
22 }
View Code

 

Suneast & Daxia (规律),布布扣,bubuko.com

Suneast & Daxia (规律)

原文:http://www.cnblogs.com/ERKE/p/3582230.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!