比赛 |
2025暑期集训第7场 |
评测结果 |
AATAATTAAT |
题目名称 |
Power Calculus |
最终得分 |
60 |
用户昵称 |
xxz |
运行时间 |
14.689 s |
代码语言 |
C++ |
内存使用 |
4.06 MiB |
提交时间 |
2025-08-11 16:01:36 |
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,ans,xxz[114];
bool dfs(int x,int step){
if(step>ans||x<=0)return 0;
if(x==n)return 1;
if(x*pow(2,ans-step)<n||x/pow(2,ans-step)>n)return 0;
else if(x*pow(2,ans-step)==n)return 1;
xxz[step]=x;
for(int i=0;i<=step;i++){
if(dfs(x+xxz[i],step+1)||dfs(x-xxz[i],step+1)){
return 1;
}
}
return 0;
}
signed main(){
freopen("pow_cal.in","r",stdin);freopen("pow_cal.out","w",stdout);
while(cin>>n){
if(!n)break;
ans=0;
if(n==1)printf("0\n");
else
{
while(!dfs(1,0)){
ans++;
}
printf("%lld\n",ans);
}
}
return 0;
}