CF1368B. Codeforces Subsequences

思路

找出最小的\(a_1*a_2*a_3*a_4*a_5*a_6*a_7*a_8*a_9*a_{10} <= n\)

ac代码

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;
const i64 inf = 1e18;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
const int N = 3e5 + 10;

void solve() {
    i64 n;
    cin >> n;
    string s = "codeforces";
    int cnt[11];
    for (int i = 0; i <= 10; i++) cnt[i] = 1;
    int idx = 0;
    while (1) {
        i64 tmp = 1;
        for (int i = 0; i < 10; i++)
            tmp *= cnt[i];
        if (tmp >= n) {
            for (int i = 0; i < 10; i++) 
                cout << string(cnt[i], s[i]);
            return;
        }

        cnt[idx ++] ++;
        idx %= 10;
    }
}   

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);

    int t = 1;
    //cin >> t;
    while (t --) solve();

    return 0;
}
posted @ 2024-01-22 00:10  jvdyvan  阅读(9)  评论(0)    收藏  举报