// This version of the code uses a static array of counts for it seems that // megabyte stackframes are queasy. // This version seems to work. // Link with code at http://cap-lore.com/code/shran.c #include #include typedef unsigned int u32; typedef struct{u32 st[5]; int bc;} prngS; // Don't peek! int Rand(prngS *, int n); prngS gg(long long); #define prec 6 typedef unsigned short uc; typedef struct{u32 a[prec];} b; #define C const prngS rss; static b sri(C b z){b x; int j, k; for(j=0; j=0; --k) if(z.a[j] & (1< z.a[j]) goto more; {int m; for(m = j+1; m < prec; ++m) {x.a[m] = Rand(&rss, 28); if (x.a[m] > z.a[m]) goto more; if (x.a[m] < z.a[m]) return fill(m);}} more: ; }} static void addTo(b* x, b* y) {int j = prec, c=0; while(j--) { int q = x->a[j] + y->a[j] + c; c = q>>28; x->a[j] = q & ((1<<28)-1);} if(c) {printf("Overflow\n"); exit(3);}} static void subFrm(b* x, b* y) {int j = prec, c=0; while(j--) { int q = x->a[j] - y->a[j] - c; if(q<0) {x->a[j] = q + (1<<28); c = 1;} else {x->a[j] = q; c = 0;}} if(c) {printf("Underflow\n"); exit(3);}} static int div10(b* x){int c = 0, j; for(j=0; ja[j]; x->a[j] = n/10; c = n%10;} return c;} static void pr(b x){char d[51]; int j = 51; while(j--) d[j] = div10(&x) + '0'; for(j=0; j<51; ++j) putchar(d[j]);} static b sb(int j){b x; int k=prec; while(k--) x.a[k]=0; x.a[prec-1] = j; return x;} static b s2b(char * s){b x; {int j=prec; while(j--) x.a[j]=0;} while(*s){char d = *s; if(d < '0' || d > '9') {printf("non digit!\n"); exit(3);} addTo(&x, &x); {b y = x; addTo(&y, &y); addTo(&y, &y); addTo(&x, &y);} {b y = sb (d - '0'); addTo(&x, &y); ++s;}} return x;} static int less(b*x, b*y) {int j; for(j=0; ja[j] < y->a[j]) return 1; else if(x->a[j] > y->a[j]) return 0; return 0;} #define pxc 2700 #define sz 16 static b szs[sz][pxc]; static int fbex; static uc pats[pxc]; static void ps(char * s){int j, k; for(k=0; k>k)&1?"* ":" ");} printf("\n");}}} int main(){ int fa=1, fb=1; {int j=sz; while(j--) {int t = fa; fa = fb; fb += t;} fbex = fb;} if(fb > pxc) {printf("Foo\n"); exit(3);} rss = gg(43); {b b0 = sb(0), b1 = sb(1); {int j = 1<