CF 1368B Codeforces Subsequences

Karl likes Codeforces and subsequences. He wants to find a string of lowercase English letters that contains at least k subsequences codeforces. Out of all possible strings, Karl wants to find a shortest one.

Formally, a codeforces subsequence of a string s is a subset of ten characters of s 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 k codeforces subsequences.

Input
The only line contains a single integer k (1≤k≤1016).

Output
Print a shortest string of lowercase English letters that contains at least k codeforces subsequences. If there are several such strings, print any of them.

Examples
input
1
output
codeforces
input
3
output
codeforcesss


题意

在字符串 s s s 的子串中( 子串可以不连续 ),包含至少 k k k c o d e f o r c e s codeforces codeforces最短字符串 s s s

思路

因为子串可以不连续,所以 s s s c o d e f o r c e s codeforces codeforces 的数量 = 每个字符数量的乘积。

#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
typedef long long ll;

const int N = 20;

int cnt[N];

int main()
{
	string st = "codeforces";

	ll n; cin >> n;

	for (int i = 0; i < 10; i++) cnt[i] = 1;

	int j = 0;

	while (true)
	{
		ll res = 1;
		for (int i = 0; i < 10; i++) res *= cnt[i];

		if (res >= n) break;

		cnt[(j++) % 10]++;

	}

	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < cnt[i]; j++) cout << st[i];
	}
	cout << endl;

	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值