【牛客 - 302哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(低年级)】 小乐乐算数字(水题,快速幂,lowbit)

版权声明:欢迎学习我的博客,希望ACM的发展越来越好~ https://blog.csdn.net/qq_41289920/article/details/84728490

题干:

小乐乐最喜欢玩数字了。

小乐乐最近迷上了2这个整数,他觉得2的幂是一种非常可爱的数字。

小乐乐想知道整数x的最大的 2的幂 (2^y)的因子。

y为整数。

输入描述:

输入整数x。(1<=x<=1e18)

输出描述:

输出整数x的最大(2^y)的因子。

示例1

输入

复制

7

输出

复制

1

说明

2^0

示例2

输入

复制

8

输出

复制

8

示例3

输入

复制

6

输出

复制

2

备注:

7的最大(2^x)的因子是:1

8:8

6:2

解题报告:

  当个水题存下来以后给学弟做2333、、、

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
char s[400][400];
int main()
{
	ll x;
	cin>>x;
	ll up = (ll)log2(x);
	for(ll i = up; i>=0; i--) {
		if(x%(ll)pow(2,i) == 0) {
			printf("%lld\n",(ll)pow(2,i));return 0 ;
		}
	}
	return 0 ;
 }

好像标解不是这样的,,是直接输出一个lowbit,,,想想也确实。。。没毛病啊、、

猜你喜欢

转载自blog.csdn.net/qq_41289920/article/details/84728490