CodeForces - 690A2 Collective Mindsets (medium) 找规律

A2. Collective Mindsets (medium)

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?

The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.

Input

The only line of input contains one integer: N, the number of attendees (1 ≤ N ≤ 109).

Output

Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.

Examples

input

Copy

1

output

Copy

0

input

Copy

3

output

Copy

1

input

Copy

99

output

Copy

49

 

 

找规律;

通过前16个可以发现:

奇数除以二就行了;

偶数有如下规律:

0                                                                            2

0   1                                                                       4   6

0   1    2    3                                                           8    10    12   14

0   1    2    3    4   5   6  7                                       16   18    20   22   24   26   28  30

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    while(cin >> n){
        if(n%2==1)
            cout << n/2 << endl;
        else{
            int ans = 1;
            while(ans <= n){
                ans *= 2;
            }
            cout << (n-ans/2)/2 <<endl;
        }
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值