~~加一个特判~~
by zty52 @ 2019-10-29 15:20:47
开long long ,最后可能会加爆
by big_news @ 2019-11-09 17:12:12
~~加一个特判~~
by 小黄鸭GC @ 2020-03-02 15:28:24
那一长串使用一个简单地东西
```
int n=100;
long long x=1;
while(n--) x*=2,cout<<x<<",";
```
测试出来的
所以就成了这样
```c
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
const int N = int(1e7+1);
int a[N],b[N];
int c,d,i,n,j,k,ans(0);
long long sum(0);
long long t[10000]={0,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,4294967296};
inline int read() {//快读
int x(0),y(1);char c=getchar();
while(c<'0'||c>'9') {
if(c=='-')y=-1;
c=getchar();
}
while(c>='0'&&c<='9') {
x=(x<<1)+(x<<3)+(c^48);
c=getchar();
}
return x*y;
}
inline void write(int x) {//快写
if(x<0) {
putchar('-');
x=-x;
write(x);
} else {
if(x>9) {
write(x/10);
}
putchar(x%10+'0');
}
}
//妄想卡场然而并没有卵用
//于是
int main()
{
n=read();
k=read();
int i=0;
if(k==1){//另类特判,答案一定是2的n次方减n
//貌似之前还有一个k=1的点极其迅速……
for(int i=1;i<=35;i++)
if(n<=t[i])
{
cout<<t[i]-n;
return 0;
}
}//所以你可以叫他另类剪枝??不确定
while(n)
{
i++;
a[i]=n%2;
n/=2;
}
register int sum1(0);
register int m(i);
register int j(0);
for(i=1;i<=m;++i)
if(a[i]==1) sum1++;
while(sum1>k)
{
++ans;
sum=0;
if(a[1]==1)
{
a[1]=2;
for(i=1;i<=m;++i)
{
if(a[i]==2) a[i+1]++,a[i]=0;
if(a[m+1]==1) m++;
}
sum1=0;
for(i=1;i<=m;++i)
if(a[i]==1)
sum1++;
}
else
a[1]=1,sum1++;
}
write(ans);
return 0;
}
```
by shx0519 @ 2022-08-25 12:51:06