ACdream 1020 The Game about KILL

找规律。

1
1 3 
1 3 5 7
1 3 5 7 9 11 13 15

.......

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}

const int maxn=40;
LL a[maxn],b[maxn];

int main()
{
    a[1]=1; b[0]=0;
    for(int i=2;i<=31;i++) a[i]=2*a[i-1];
    for(int i=1;i<=31;i++) b[i]=b[i-1]+a[i];
    LL n;

    while(~scanf("%lld",&n))
    {
        for(int i=1;i<=31;i++)
        {
            if(b[i]<=n) continue;
            else
            {
                LL x=n-b[i-1]; if(x==0) x=a[i-1];
                printf("%lld\n",1+(x-1)*2);
                break;
            }
        }
    }
    return 0;
}

 

posted @ 2016-08-17 21:46  Fighting_Heart  阅读(133)  评论(0编辑  收藏  举报