Problem:
Problem C:
Champernowne Constant
Champernown constant is an irrational number represented in decimal by "
0.
" followed by
concatenation of all positive integers in the increasing order. The first few digits of this constant
are: 0.123456789101112...
Your task is to write a program that outputs the
K
digits of Chapnernown constant starting at
the
N
-th place for given two natural numbers
K
and
N
.
Input
The input has multiple lines. Each line has two positive integers
N
and
K
(
N
≤ 10
9
,
K
≤ 100)
separated by a space.
The end of input is indicated by a line with two zeros. This line should not be processed.
Output
For each line, output a line that contains the
K
digits.
Sample Input
4 5
6 7
0 0
Output for the Sample Input
45678
6789101

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

int n, k;

string solve();
int check(int x);

int main() {
  while (1) {
    cin >> n >> k;
    if (!(n + k)) break;
    cout << solve() << endl;
  }
  return 0;
}

string solve() {
  int l = 0, r = 200000000;
  while (r - l > 1) {
    int mid = (l + r) >> 1;
    if (check(mid) >= n)
      r = mid;
    else
      l = mid;
  }
  map<int, char> mp;
  for (int i = r, now = check(l); i <= r + 1000; ++i)
    for (auto c : to_string(i)) mp[++now] = c;
  string res;
  for (int i = n; i < n + k; ++i) res += mp[i];
  return res;
}

int check(int x) {
  int res = 0, ten = 1;
  for (int i = 1; i <= 9; ++i) {
    int last = min(ten * 10 - 1, x);
    res += i * (last - ten + 1);
    if (last == x) break;
    ten *= 10;
  }
  return res;
}
accuracy: 1
time_ms: 20
memory_kb: 3616
final_rank: 9

code_snippet: #include<iostream>
using namespace std;
long n,k;
main()
{
	while(cin>>n>>k,n)
	{
		n--;
		int now=1,keta=1,test=10;
		while(n>=keta)
		{
			n-=keta;
			now++;
			if(now%test==0)
			{
				test*=10;
				keta++;
			}
		}
		if(n>0)
		{
			string out="";
			int tmp=now;
			for(int i=0;i<keta-n;i++)
			{
				out=(char)(tmp%10+'0')+out;
				tmp/=10;
			}
			if(k>=keta-n)cout<<out;
			else
			{
				for(int i=0;i<k;i++)cout<<out[i];
			}
			k-=keta-n;
			now++;
		}
		while(k>0)
		{
			int cnt=0,tmp=now;
			string out="";
			while(tmp)cnt++,out=(char)(tmp%10+'0')+out,tmp/=10;
			if(k>=cnt)
			{
				k-=cnt;
				cout<<out;
			}
			else
			{
				for(int i=0;i<k;i++)cout<<out[i];
				k=0;
			}
			now++;
		}
		cout<<endl;
	}
}
accuracy: 1
time_ms: 5700
memory_kb: 3148
final_rank: 11

code_snippet: #include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

// [1,x) で必要な文字数
ll calc(ll x)
{
    string s = to_string(x);
    ll n = s.length();
    ll res = 0;
    for (ll i = 1; i <= n - 1; i++)
    {
        res += 9 * i * pow(10, i - 1);
    }
    res += n * (x - pow(10, n - 1));
    return res;
}

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

    // N 桁目から K 文字
    ll N, K;
    while (cin >> N >> K, N || K)
    {
        string s = "0";
        for (int i = 1; i <= 9999; i++)
        {
            s += to_string(i);
        }
        if (N + K - 1 < (int)s.length())
        {
            cout << s.substr(N, K) << endl;
            continue;
            ;
        }
        ll low = 1, high = 1e9;
        for (int i = 0; i < 50; i++)
        {
            ll mid = (low + high) / 2;
            if (calc(mid) >= N)
            {
                high = mid;
            }
            else
            {
                low = mid;
            }
        }
        string res = "0";
        for (int i = low; i <= low + 100; i++)
        {
            res += to_string(i);
        }
        cout << res.substr(N - calc(low), K) << endl;
    }
}
accuracy: 1
time_ms: 50
memory_kb: 3524
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll len(ll x){
  ll a=1,k=0,j=1;
  while(a*10<=x) k+=9*a*j,a*=10,j++;
  k+=(x-a+1)*j;
  return k;
}
int main(){
  ll n,k;
  while(cin>>n>>k,n||k){
    ll l=0,r=1000000000LL,m,i;
    string s;
    while(l+1<r) (len(m=(l+r)/2)<n)?l=m:r=m;
    for(i=1;i<10000;i++) s+=to_string(l+i);
    for(i=0;i<k;i++) cout << s[n-len(l)-1+i];
    cout << endl;      
  }
  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3344
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    while(true){
        ll n,k;
        cin >> n >> k;
        if(n==0 and k==0) break;

        ll x,y;
        rep(i,1,inf){
            ll tmp=i*(pow(10,i)-pow(10,i-1));
            if(n-tmp>0) n-=tmp;
            else{
                x=pow(10,i-1);
                y=i;
                break;
            }
        }

        ll a=0;
        rep(i,1,11){
            if(n-y*x>0) n-=y*x;
            else{
                a=i;
                break;
            }
        }

        ll b=0;
        rep(i,1,11){
            if(n-y*x/10>0) n-=y*x/10;
            else{
                b=i-1;
                break;
            }
        }

        ll c=0;
        rep(i,1,11){
            if(n-y*x/100>0) n-=y*x/100;
            else{
                c=i-1;
                break;
            }
        }

        ll d=0;
        rep(i,1,11){
            if(n-y*x/1000>0) n-=y*x/1000;
            else{
                d=i-1;
                break;
            }
        }

        ll e=0;
        rep(i,1,11){
            if(n-y*x/10000>0) n-=y*x/10000;
            else{
                e=i-1;
                break;
            }
        }

        stringstream ss;
        rep(i,0,100000){
            ss << x*a+x*b/10+x*c/100+x*d/1000+x*e/10000+i;
            if(ss.str().size()>n+k) break;
        }
        cout << ss.str().substr(n-1,k) << endl;
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(8);
    solve();
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3436
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    while(true){
        ll n,k;
        cin >> n >> k;
        if(n==0 and k==0) break;

        ll x,y;
        rep(i,1,inf){
            ll tmp=i*(pow(10,i)-pow(10,i-1));
            if(n-tmp>0) n-=tmp;
            else{
                x=pow(10,i-1);
                y=i;
                break;
            }
        }
        dump(x);
        dump(y);
        dump(n);

        ll z=0;
        rep(i,1,11){
            if(n-y*x>0) n-=y*x;
            else{
                z=i;
                break;
            }
        }
        dump(z);
        dump(n);
        ll w=0;
        rep(i,1,11){
            if(n-y*x/10>0) n-=y*x/10;
            else{
                w=i-1;
                break;
            }
        }
        dump(w);
        dump(n);
        ll hoge=0;
        rep(i,1,11){
            if(n-y*x/100>0) n-=y*x/100;
            else{
                hoge=i-1;
                break;
            }
        }
        dump(hoge);
        ll piyo=0;
        rep(i,1,11){
            if(n-y*x/1000>0) n-=y*x/1000;
            else{
                piyo=i-1;
                break;
            }
        }
        dump(piyo);
        dump(n);
        stringstream ss;
        rep(i,0,100000){
            ss << x*z+x*w/10+x*hoge/100+x*piyo/1000+i;
            //dump(ss.str().size());
            if(ss.str().size()>n+k) break;
        }
        cout << ss.str().substr(n-1,k) << endl;
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(8);
    solve();
    return 0;
}
accuracy: 1
time_ms: 6740
memory_kb: 5264
final_rank: 12

code_snippet: #include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;

typedef long long lli;

string toString(const lli &i) {
  char buff[128];
  sprintf(buff, "%lld", i);
  return string(buff);
}

int main() {
  lli N, K;
  while(cin >> N >> K && (N|K)) {
    string tmp = "";
    lli cnt = 1;
    lli i, t, n;
    for(i = 1, t = 10, n = 1; ; ++i) {
      if(i == t) {
        ++n;
        t *= 10;
      }
      cnt += n;
      if(cnt > N) {
        cnt -= n;
        break;
      }
    }
    for(; cnt < N+K; ++i) {
      string s = toString(i);
      cnt += s.size();
      tmp += s;
    }
    cout << tmp.substr(tmp.size()-(cnt-N), K) << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 1450
memory_kb: 1248
final_rank: 3

code_snippet: #include<iostream>
#include<sstream>
#include<string>
typedef long long ll;

using namespace std;

string IntToString(int n){
  stringstream ss;
  ss << n;
  return ss.str();
}

string ChampernowneConstant(ll n, ll m){
  ll i, j, k, sum=0;
  for(i=1, j=1; n > sum + 9*i*j; ++i, j*=10) sum += 9*i*j;
  for(j; n > sum+i; ++j) sum += i;

  string str_ = IntToString(j);
  string str(str_.begin()+(n-sum-1), str_.end());

  while(str.size() < m){
    ++j;
    str.append(IntToString(j));
  }
  str.erase(str.end()-(str.size()-m), str.end());
  return str;
}

int main(){
  ll n, m;
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    cout << ChampernowneConstant(n, m) << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 510
memory_kb: 1224
final_rank: 2

code_snippet: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
string itos(int N){
  stringstream ss;
  ss<<N;
  return ss.str();
}

int main(){
  int N, K;
  while(cin>>N>>K && N){
    int cur = 1;
    int ten[10] = {};
    ten[1] = 10;
    for(int i = 1; i < 9; i++) ten[i + 1] = ten[i] * 10;
    int dig = 1;
    string output;
    N--;
    while(N > 0){
      if(N - dig < 0){
        string s = itos(cur);
        output += s.substr(N);
      }
      N -= dig;
      cur++;
      if(ten[ dig ]==cur) dig++;
    }
    while(output.size() < K){
      output += itos(cur++);
    }
    cout<<output.substr(0, K)<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 6180
memory_kb: 1224
final_rank: 10

code_snippet: #include<stdio.h>
#include<sstream>
#include<string>
int F(int x)
{
	int d=1,t=1,r=0;
	while(d*10<=x)
	{
		r+=d*9*t;
		d*=10;
		++t;
	}
	return r+(x-d+1)*t;
}
int main()
{
	int N,K,l,m,r,i;
	while(scanf("%d%d",&N,&K),N)
	{
		for(l=1,r=13e7;l<r;)
		{
			m=(l+r)/2;
			if(F(m)<N)l=m+1;
			else r=m;
		}
		std::stringstream s;
		for(i=l;s.str().size()<=K*K;++i)
			s<<i;
		printf("%s\n",s.str().substr(N-F(l-1)-1,K).c_str());
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,k;

int main(){
	while(cin>>n>>k&&n){
		n--;
		int cur=1,d=1,p=10;
		while(1){
			if(n-d<0)break;
			n-=d;
			cur++;
			if(cur==p)d++,p*=10;
		}
		string a;
		while(a.sz<k){
			sst ss;
			ss<<cur++;
			a+=ss.str().substr(n);
			n=0;
		}
		cout<<a.substr(0,k)<<endl;
	}
}
accuracy: 1
time_ms: 2330
memory_kb: 940
final_rank: 4

code_snippet: #include<iostream>
#include<sstream>
using namespace std;
typedef long long ll;
ll pw(ll b,ll e){
	ll i,r=1;
	for(i=0;i<e;i++)r*=b;
	return r;
}
int main(){
	ll n,k;
	while(cin>>n>>k,n){
		ll m,s,r;
		for(m=1;n>9*m*pw(10,m-1);m++)n-=9*m*pw(10,m-1);
		for(r=0;n>m;r++)n-=m;
		s=pw(10,m-1)+r;
		stringstream ans;
		while(ans.str().size()<=k+n)ans<<s++;
		cout<<ans.str().substr(n-1,k)<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 2550
memory_kb: 932
final_rank: 5