無限の光を放つのは人間の心であり、無限の闇を生み出すのも人間の心であり、光と闇が絡み合って戦うこの世界は、懐かしくて無力な世界です。
Look-and-Sayシーケンスは、次のような整数のシーケンスです。
D, D1, D111, D113, D11231, D112213111, ...
ここ D
で、1を除く[0、9]です。(n + 1)番目の数は、n番目の数の一種の記述です。たとえば、2番目の数値はD
、1番目の数値に1 つあることを意味し D1
ます。したがって 、2番目の数は1 D
(に対応 D1
)と1(11に対応)で構成されているため、3番目の数は D111
です。第四の数であるためか D113
、それが1で構成され D
、2 1つの、及び1 3を、その次の番号がなければなりません D11231
。この定義は D
= 1でも機能します。ここで、指定された数字のLook&SayシーケンスのN番目の数値を計算することになっています D
。
入力仕様:
各入力ファイルには、D
([0、9]で)およびスペースで区切られた正の整数N(≤40)を与える1つのテストケースが含ま れています。
出力仕様:
の見た目のシーケンスのN番目の数値を1行に出力します D
。
入力例:
1 8
出力例:
1123123111
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
//#include<bits/stdc++.h>
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
#define PI 3.1415926
typedef long long ll;
using namespace std;
int const mod=1e9+7;
const int maxn=1e5+10;
int d, n;
int main() {
scanf("%d %d", &d, &n);
vector<int> V;
V.push_back(d);
for (int i=1; i<n; i++) {
vector<int> ls;
int v=V[0];
int ct=0;
for (int j=0; j<V.size(); j++) {
if (V[j]==v)
ct++;
else{
ls.push_back(v);
ls.push_back(ct);
ct=1;
v=V[j];
}
if (j==V.size()-1) {
ls.push_back(v);
ls.push_back(ct);
}
}
V=ls;
}
for (int i=0; i<V.size(); i++)
printf("%d", V[i]);
return 0;
}