B. Codeforces Subsequences
Karl likes Codeforces and subsequences. He wants to find a string of lowercase English letters that contains at least kk subsequences codeforces. Out of all possible strings, Karl wants to find a shortest one.
Formally, a codeforces subsequence of a string ss is a subset of ten characters of ss that read codeforces from left to right. For example, codeforces contains codeforces a single time, while codeforcesisawesome contains codeforces four times: codeforcesisawesome, codeforcesisawesome, codeforcesisawesome, codeforcesisawesome.
Help Karl find any shortest string that contains at least kk codeforces subsequences.
The only line contains a single integer kk (1≤k≤1016)1≤k≤1016).
Print a shortest string of lowercase English letters that contains at least kk codeforces subsequences. If there are several such strings, print any of them.
1
codeforces
3
codeforcesss
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <set> #include <queue> #include <map> #include <sstream> #include <cstdio> #include <cstring> #include <numeric> #include <cmath> #include <iomanip> #include <deque> #include <bitset> //#include <unordered_set> //#include <unordered_map> #define ll long long #define pii pair<int, int> #define rep(i,a,b) for(int i=a;i<=b;i++) #define dec(i,a,b) for(int i=a;i>=b;i--) #define forn(i, n) for(int i = 0; i < int(n); i++) using namespace std; int dir[4][2] = { { 1,0 },{ 0,1 } ,{ 0,-1 },{ -1,0 } }; const long long INF = 0x7f7f7f7f7f7f7f7f; const int inf = 0x3f3f3f3f; const double pi = 3.14159265358979323846; const double eps = 1e-6; const int mod = 1e9 + 7; const int N = 3e3 + 5; //if(x<0 || x>=r || y<0 || y>=c) inline ll read() { ll x = 0; bool f = true; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f ? x : -x; } ll gcd(ll m, ll n) { return n == 0 ? m : gcd(n, m % n); } ll lcm(ll m, ll n) { return m * n / gcd(m, n); } bool prime(int x) { if (x < 2) return false; for (int i = 2; i * i <= x; ++i) { if (x % i == 0) return false; } return true; } ll qpow(ll m, ll k, ll mod) { ll res = 1, t = m; while (k) { if (k & 1) res = res * t % mod; t = t * t % mod; k >>= 1; } return res; } bool check(string s,string s1) { int cnt = 0; forn(i, s.size()) { if (s[i] != s1[i]) cnt++; } if (cnt > 1) return false; return true; } int main() { ll n; string s="codeforces"; cin >> n; ll m; rep(i, 1, 40) { ll a = 1; rep(j, 1, 10) { a *= i; } if (a > n) { m = i - 1; break; } } ll a=1; vector<int> cnt(10, m); rep(i, 1, 10) a *= m; int pos = 0; while (a < n) { a /= m; a *= m + 1; cnt[pos]++; pos++; } forn(i, 10) { forn(j, cnt[i]) cout << s[i]; } return 0; }