博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Suneast & Daxia (规律)
阅读量:6148 次
发布时间:2019-06-21

本文共 1799 字,大约阅读时间需要 5 分钟。

Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u

[]   [Go Back]   []  

Description

Daxia is so cute that people loves it so much.

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

 

 

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

125

Sample Output

123

Hint

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

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

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

呵呵,这题看师兄的才懂了!
 
1 #include 
2 #include
3 #include
4 #include
5 #include
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<
<
View Code

 

转载于:https://www.cnblogs.com/ERKE/p/3582230.html

你可能感兴趣的文章
C++ 11 lambda
查看>>
Hadoop2.5.0 搭建实录
查看>>
实验吧 recursive write up
查看>>
Android JSON数据解析
查看>>
DEV实现日期时间效果
查看>>
java注解【转】
查看>>
Oracle表分区
查看>>
centos 下安装g++
查看>>
嵌入式,代码调试----GDB扫盲
查看>>
类斐波那契数列的奇妙性质
查看>>
配置设置[Django]引入模版之后报错Requested setting TEMPLATE_DEBUG, but settings are not configured....
查看>>
下一步工作分配
查看>>
Response. AppendHeader使用大全及文件下载.net函数使用注意点(转载)
查看>>
Wait Functions
查看>>
代码描述10313 - Pay the Price
查看>>
jQuery最佳实践
查看>>
centos64i386下apache 403没有权限访问。
查看>>
vb sendmessage 详解1
查看>>
jquery用法大全
查看>>
PC-BSD 9.2 发布,基于 FreeBSD 9.2
查看>>