B. Codeforces S
B. Codeforces Subsequences
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output
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.
Input
The only line contains a single integer kk (1≤k≤1016)1≤k≤1016).
Output
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.
Examples
input
Copy
1
output
Copy
codeforces
input
Copy
3
output
Copy
codeforcesss
ubsequences
=========================================================================
首先不在字母本位置上进行增加是不会获得最大效果的,最终的答案就是各个字母个数的乘积。
原来是
1 1 1 1 1 1 1 1 1 1
加1的话,放在那个位置都行
2 1 1 1 1 1 1 1 1 1
再加1的话,可以加到2,也可以加到1,但是发现加到1带来的增效更高
2 2 1 1 1 1 1 1 1 1
再增加1也是同理,即尽量让10个字母数量相同能够使得最终个数最多
那么我们就一直这样暴力循环,每个最多不到100次,10个也就不到1000次循环就能超过k
#include<iostream>
#include<cstdio>
#include<cstring>
# include<iomanip>
#include<algorithm>
#define mo 998244353;
using namespace std;
typedef long long int ll;
ll cnt[20];
char ans(int i)
{
string s=" codeforces";
return s[i];
}
int main()
{
ll n;
cin>>n;
for(int i=1;i<=10;i++)
{
cnt[i]=1;
}
ll now=1;
int t=1;
while(now<n)
{
now=now/cnt[t]*(cnt[t]+1);
cnt[t]++;
t++;
if(t==11)
t=1;
}
for(int i=1;i<=10;i++)
{
for(int j=1;j<=cnt[i];j++)
{
cout<<ans(i);
}
}
return 0;
}