Путь: Toys/Other, команды версии: Ver.4 Ver.9 factor Комментарии в файле factor.c :
Исходный текст в файле factor.c #define FOR_factor #include "toys.h" static void factor(char *s) { unsigned long long l, ll, lll; char *pat1 = FLAG(x) ? " %llx" : " %llu", *pat2 = FLAG(x) ? "^%x" : "^%u"; for (;;) { char *err = s; int dash = 0, ii; while(isspace(*s)) s++; if (*s=='-') dash = *s++; if (!*s) return; errno = 0; l = strtoull(s, &s, 0); if (errno || (*s && !isspace(*s))) { error_msg("%s: not integer", err); while (*s && !isspace(*s)) s++; continue; } if (dash) xputc('-'); printf(pat1+1, l); xputc(':'); // Negative numbers have -1 as a factor if (dash) printf(" -1"); // test 2 and odd numbers until square is > remainder or integer wrap. for (ll = 2;; ll += 1+(ll!=2)) { lll = ll*ll; if (lll>l || lll<ll) { if (l>1 || ll==2) printf(pat1, l); break; } for (ii = 0; !(l%ll); ii++) { if (!ii || !FLAG(h)) printf(pat1, ll); l /= ll; } if (ii>1 && FLAG(h)) printf(pat2, ii); } xputc('\n'); } } void factor_main(void) { char *s = 0, **ss; size_t len = 0; if (toys.optc) for (ss = toys.optargs; *ss; ss++) factor(*ss); else for (;;) { if (-1 == getline(&s, &len, stdin)) break; factor(s); } } |