跳到正文

个人记录

课外1-[NOIP 1998 普及组] 幂次方

obbycode约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年10月18日
收录
2026年10月18日
更新
2026年11月13日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
void solve(int n)
{
    if(n==0)
    {
        cout<<"0";
        return;
    }
    bool first=true;//第一个数
    for(int i=31;i>=0;i--)
    {
        if(n&(1<<i))
        {
            if(!first) cout<<"+";//第一个数不要+号
            first=false;
            if(i==0) cout<<"2(0)";
            else if(i==1) cout<<"2";
            else
            {
                cout<<"2(";
                solve(i);
                cout<<")";
            }
        }
    }
}
int main()
{
    int n;
    cin>>n;
    solve(n);
    return 0;
}
原文