Ural 1079 - Maximum

Consider the sequence of numbers aii = 0, 1, 2, …, which satisfies the following requirements:
  • a0 = 0
  • a1 = 1
  • a2i = ai
  • a2i+1 = ai + ai+1

for every i = 1, 2, 3, … .

Write a program which for a given value of n finds the largest number among the numbers a0a1, …,an.

Input

You are given several test cases (not more than 10). Each test case is a line containing an integern (1 ≤ n ≤ 99 999). The last line of input contains 0.

Output

For every n in the input write the corresponding maximum value found.

Sample

input output
5
10
0
3
4
Problem Author: Emil Kelevedzhiev
Problem Source: Winter Mathematical Festival Varna '2001 Informatics Tournament
// Ural Problem 1079. Maximum
// Verdict: Accepted
// Submission Date: 14:33:08 15 Jan 2014
// Run Time: 0.031s
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/// [解题方法]
// 简单题模拟题
// 注意:最大项有可能是奇数项 #include<stdio.h> long long a[], b[]; void solve()
{
int i, j, max, n;
a[] = b[] = ;
a[] = b[] = ;
max = ;
for(i = ; i < ; i++) {
if(i % ) {
j = (i - ) >> ;
a[i] = a[j] + a[j + ];
} else {
a[i] = a[i >> ];
}
if(a[i] > max)
max = a[i];
b[i] = max;
}
while(scanf("%d", &n) && n) {
printf("%lld\n", b[n]);
}
} int main()
{
solve();
return ;
}
上一篇:14门Linux课程,打通你Linux的任督二脉!


下一篇:maven GroupId 和ArtifactId的含义