Advertisement
Guest User

bignum

a guest
Aug 7th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. int a=9<<9e9;
  2. struct S{ int rank; int value; S **list; };
  3. S *max(int x){
  4. S *s=new S();s->rank=x;s->value=a;
  5. if(x==0){s->list=0;return s;}
  6. s->list=new S *[a+1];
  7. for(int i=0;i<a;++i){s->list[i]=max(x-1);}s->list[a]=0;
  8. return s;
  9. }
  10. S *dup(S *s)
  11. {
  12. if(s==0)return s;
  13. S *x=new S();
  14. x->rank=s->rank;x->value=s->value;
  15. if(s->list==0){x->list=s->list;return x;}
  16. int i=0;
  17. while(s->list[i])++i;
  18. x->list=new S *[i+1];
  19. while(i>=0){x->list[i]=dup(s->list[i]);--i;}
  20. return x;
  21. }
  22. bool next(S *s){
  23. if(s==0)return true;
  24. if(s->rank==0) return (--s->value)!=0;
  25. int i=0;
  26. while(!next(s->list[i])){s->list[i]=max(s->list[i]->rank);++i;}
  27. if(!s->list[i])return (--s->value)!=0;
  28. return true;
  29. }
  30. void f(S *s){
  31. a++;
  32. if(!next(s))return;
  33. S *t=max(a);
  34. while(next(t))f(dup(s));
  35. }
  36. int main()
  37. {
  38. f(max(a));
  39. return a;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement