题干:
小乐乐最喜欢玩数字了。
小乐乐最近迷上了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,,,想想也确实。。。没毛病啊、、