Advertisement
Bodigrim

Three Sons Problem

Aug 10th, 2011
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. magic(n) = n^2*(n^2+1)*(n^2-2*n+2);
  2.  
  3. three_sons(n) = {
  4. local(nfactor, f, count_outer, count_inner, xx, zz, k, x, y, z, b, c, det, detrt, ret);
  5.  
  6. if(moebius(n) != 0, return(0));
  7.  
  8. nfactor = factor(n);
  9.  
  10. f = core(n,1)[2];
  11.  
  12. if(magic(f)<n, return(0));
  13.  
  14. count_outer = 0;
  15.  
  16. fordiv(f, xx,
  17. if(xx == 1, next);
  18. if(xx^3 > n, break);
  19.  
  20. if(magic(xx)<n, next);
  21.  
  22. zz = n \ xx^2;
  23. k = 2*xx + zz;
  24.  
  25. count_inner = 0;
  26.  
  27. fordiv(nfactor, x,
  28. if(x^3 >= n || 3*x >=k, break);
  29.  
  30. b = -(k-x);
  31. c = n \ x;
  32. det = b^2 - 4*c;
  33.  
  34. if(!issquare(det,&detrt), next);
  35.  
  36. y=(-b-detrt)\2;
  37. z=(-b+detrt)\2;
  38.  
  39. if(y<=x, next);
  40.  
  41. \\print([x,y,z]);
  42. ret=[x,y,z,xx,f];
  43. count_inner++;
  44.  
  45. if(count_inner>1,
  46. \\print("Two per k!");
  47. return(0));
  48.  
  49. );
  50.  
  51. if(count_inner==1, count_outer++);
  52.  
  53. if(count_outer>1,
  54. \\print("Two per n!");
  55. return(0));
  56.  
  57. );
  58.  
  59. if(count_outer != 1, return(0) );
  60.  
  61. \\print(n" "ret);
  62. return(1);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement