#include <stdio.h>
#include <stdlib.h>

char *convertToTitle(int columnNumber)
{
    char *ret = malloc(2);
    int size = 1;

    while (columnNumber > 0)
    {
        columnNumber--;
        const int mod = columnNumber % 26;
        columnNumber /= 26;
        ret[size - 1] = 'A' + mod;

        size++;
        ret = realloc(ret, size + 1);
    }

    ret[size - 1] = '\0';

    for (int i = 0, j = size - 2; i < j; i++, j--)
    {
        const char tmp = ret[i];
        ret[i] = ret[j];
        ret[j] = tmp;
    }

    return ret;
}

int main()
{
    char *ans = convertToTitle(2147483647);
    printf("%s\n", ans);
    free(ans);
    return 0;
}
