最低位 【杭电-HDOJ-1196】 附题

/*

Lowest Bit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 7775    Accepted Submission(s): 5714

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

#include<stdio.h>
#include<string.h>
int main()
{
	int n;
	while(~scanf("%d",&n),n)
	{
		//printf("%d\n",n&(-n));
		printf("%d\n",n^(n&(n-1)));
	}
	return 0;
}

时间: 2024-08-11 03:22:51

最低位 【杭电-HDOJ-1196】 附题的相关文章

循环多少次? 【杭电--HDOJ-1799】 附题

/* 循环多少次? Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2839    Accepted Submission(s): 1028 Problem Description 我们知道,在编程中,我们时常需要考虑到时间复杂度,特别是对于循环的部分.例如, 如果代码中出现 for(i=1;i<=n;i++) OP ; 那么做了n次O

整除的尾数 【杭电-2099】 附题

/* 整除的尾数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 23096    Accepted Submission(s): 9792 Problem Description 一个整数,只知道前几位,不知道末二位,被另一个整数除尽了,那么该数的末二位该是什么呢? Input 输入数据有若干组,每组数据包含二个整数a,b(0<a<

大菲波数 【杭电-HDOJ-1715】 附题

/* 大菲波数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 11168    Accepted Submission(s): 3782 Problem Description Fibonacci数列,定义如下: f(1)=f(2)=1 f(n)=f(n-1)+f(n-2) n>=3. 计算第n项Fibonacci数值. Input

2^x mod n = 1 【杭电-HDOJ-1395】 附题

/* 2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11800    Accepted Submission(s): 3673 Problem Description Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.

最小公倍数 【杭电-HDOJ-1108】 附题+详解

/* 最小公倍数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 32933    Accepted Submission(s): 18398 Problem Description 给定两个正整数,计算这两个数的最小公倍数. Input 输入包含多组测试数据,每组只有一行,包括两个不大于1000的正整数. Output 对于每个测试用

求平均成绩 【杭电-HDOJ-2023】 附题+详解

/* 求平均成绩 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 62086    Accepted Submission(s): 14888 Problem Description 假设一个班有n(n<=50)个学生,每人考m(m<=5)门课,求每个学生的平均成绩和每门课的平均成绩,并输出各科成绩均大于等于平均成绩的学生数量. In

与众不同 【杭电-2095】 附题

/* find your present (2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/1024 K (Java/Others) Total Submission(s): 15255    Accepted Submission(s): 5780 Problem Description In the new year party, everybody will get a "special present&qu

小小翻译家 【杭电-1048】 附题

/* The Hardest Problem Ever Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15859    Accepted Submission(s): 7331 Problem Description Julius Caesar lived in a time of danger and intrigue. The h

大数A+B 【杭电-1002】 附题

/* A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 209912    Accepted Submission(s): 40404 Problem Description I have a very simple problem for you. Given two integers A and B,

两分数求和化最简【杭电-2503】 附题

/* a/b + c/d Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7731    Accepted Submission(s): 4462 Problem Description 给你2个分数,求他们的和,并要求和为最简形式. Input 输入首先包含一个正整数T(T<=1000),表示有T组测试数据,然后是T行数据,每行包含四