题目解析:
a=a
b=aa
c=bb=aaaa
d=cc=bbbb=aaaa,aaaa
从而观察得到:
a=2^0*a
b=2^1*a
c=2^2*a
因此对于最少表达出n个a
也就是从1,2,4,8...2^t之中选最少的数求和来表示n
代码
#include "bits/stdc++.h" using namespace std; #define int long long #define endl "\n" #define PII pair<int,int> #define PIII pair<int,PII> const int MOD = 1e9 + 7; const int N = 3e5; void slu() { int n; cin >> n; string res; while (n) { int k = 0; while (pow(2, k) <= n)k++; k--; res.push_back(('a' + k)); n -= pow(2, k); } cout << res; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T; // cin >> T; T = 1; while (T--)slu(); }