有没有大佬知到为啥我刚刚读入就TLE了
查看原帖
有没有大佬知到为啥我刚刚读入就TLE了
722656
liuergou楼主2023/10/7 22:32
#include <bits/stdc++.h>
using namespace std;

string power(int n){
	cout << 1;
    if(n==1)return "2(0)";
    if(n==2)return "2";
    cout << 1;
    string ans="";
    int m=4,cur=3;
    while(m<n)m<<=1,cur++;
    while(n&&cur){
        if(m>n)continue;
        n-=m;
        ans+="2("+power(cur)+")+";
        while(n<m)m>>=1,cur--;
    }
    ans=ans.substr(0,ans.size()-1);
    cout << ans << endl;
    return ans;
}
int n;
int main(){
    scanf("%d",&n);
    printf ("%s",power(n));
    return 0;
}
2023/10/7 22:32
加载中...