HDU1196 Lowest Bit

题目链接

Lowest Bit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13926    Accepted Submission(s): 10063


 

Problem Description

Given an positive integer A (1 <= A <= 100), output the lowest bit of A.

For example, given A = 26, we can write A in binary form as 11010, so the lowest bit of A is 10, so the output should be 2.

Another example goes like this: given A = 88, we can write A in binary form as 1011000, so the lowest bit of A is 1000, so the output should be 8.

Input

Each line of input contains only an integer A (1 <= A <= 100). A line containing "0" indicates the end of input, and this line is not a part of the input data.

Output

For each A in the input, output a line containing only its lowest bit.

Sample Input

26

88

0

Sample Output

2 8

一下就发现一道水题。

树状数组里举足轻重的求低位函数。实现方式如下,第一种较为常见。

AC代码:

 1 #include<iostream>
 2 #include<sstream>
 3 #include<algorithm>
 4 #include<string>
 5 #include<cstring>
 6 #include<iomanip>
 7 #include<vector>
 8 #include<cmath>
 9 #include<ctime>
10 #include<stack>
11 #include<queue>
12 #define e 2.71828182
13 #define Pi 3.141592654
14 using namespace std;
15 int lowbit(int x)//常用 
16 {
17     return x&(-x);
18 }
19 /*int lowbit(int x)
20 {
21     return x&(x^(x-1));
22 }*/
23 int main()
24 {
25     int A; 
26     while(cin>>A&&A!=0)
27     {
28         cout<<lowbit(A)<<endl;
29     }
30 }
View Code
原文地址:https://www.cnblogs.com/wangzhebufangqi/p/12796131.html