I am trying to solve a problem:

Given two strings, `s` and `t`, we can form a string `x` of infinite length, as:

```
a. Append s to x 1 time;
b. Append t to x 2 times;
c. Append s to x 3 times;
d. Append t to x 4 times;
and so on...

```

Given `k`, find the `k`th character (1 indexed) in the resultant infinite string `x`.

For e.g., if s = `a`, t = `bc` and k = 4, then output: `b` (x=`abcbc`). `s` and `t` can contain anywhere from 1 to 100 characters, while 1<=`k`<=10^16.

The brute force way of actually constructing string `x` is trivial but too slow. How do I optimize it further?

In C++, the brute force solution would look like this:

```cpp
#include <iostream>
using namespace std;

int main() {
    int repeat=1, k=4;
    string s="a", t="bc", x;
    bool appendS=true;

    while(x.size()<k) {
        for(int i=1; i<=repeat; i++)
            if(appendS) x+=s;
            else x+=t;
        appendS=!appendS;
        repeat++;
    }

    cout<<x[k-1];

    return 0;
}

```

But how do I optimize it, given huge `k`?