URAL1079:Maximum

Consider the sequence of numbers ai, i = 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 a 0, a 1, …, an.

Input

You are given several test cases (not more than 10). Each test case is a line containing an integer n (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

5100

34

 

 

水题,按照公式打表即可

 

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

__int64 a[1000000];
__int64 hash[1000000];

int main()
{
    int i,j,n;
    __int64 maxn;
    a[0] = 0;
    hash[0] = 0;
    a[1] = 1;
    hash[1] = 1;
    maxn = 1;
    for(i = 2; i<=999999; i++)
    {
        if(i%2)
        {
            j = (i-1)/2;
            a[i] = a[j]+a[j+1];
        }
        else
            a[i] = a[i/2];
        if(a[i]>maxn)
            maxn = a[i];
        hash[i] = maxn;
    }
    while(~scanf("%d",&n) && n)
    {
        printf("%I64d\n",hash[n]);
    }


    return 0;
}


 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值