#include #include #include #include #define OWO "OwO" char *owo(int64_t n) { int l = strlen(OWO) + 1; char *o = malloc(n * l), *r = o; if(!o) return NULL; while(n--) { memcpy(o, OWO, l); if(n) *(o + l - 1) = ' '; o += l; } return r; } #define COPYTYPE long long char *fasterowo(int64_t n) { int lll = sizeof(COPYTYPE); int64_t l = strlen(OWO) + 1, m = 1, n2, il; char *oowo, *iowo, *rowo; COPYTYPE *ioowo, *iiowo; int64_t i, j; while((l*m) % lll) m++; n2 = (n + m-1) / m; il = l * m; if(0) fprintf(stderr, "l=%d, m=%d, n2=%d, il=%d\n", l, m, n2, il); iowo = owo(m); if(!iowo) return NULL; iowo[il - 1] = ' '; rowo = oowo = malloc(n2 * il); if(!oowo) return NULL; ioowo = (COPYTYPE *)oowo; for(i = 0; i < n2; i++) { iiowo = (COPYTYPE *)iowo; for(j = 0; j < il / lll; j++) { *ioowo = *iiowo; ioowo++; iiowo++; } } rowo[n * l - 1] = '\x0'; return rowo; } char *owoowo(int64_t n) { int l = strlen(OWO) + 1; int64_t n2 = 1, nn = n, p = 1; char *oowo; if(!n) return NULL; while(nn) { nn/=2; n2*=2;} if(n2 / 2 == n) n2 /= 2; oowo = malloc(l * n2); if(!oowo) return NULL; memcpy(oowo, OWO, l); oowo[l - 1] = ' '; while(p < n2) { memcpy(oowo + p*l, oowo, p*l); p *= 2; } oowo[n * l - 1] = '\x0'; return oowo; } void main(void) { printf("~%s~\n", owo(500000000)); printf("~%s~\n", owoowo(500000000)); printf("~%s~\n", fasterowo(500000000)); }