Fermat’s Divisors Challenges
September 8, 2015
These are easy, though they run slowly, if you already have the necessary infrastructure; note that (sigma 1 n), which computes the sum of the divisors of n, is used somewhat differently below than it was in the definition of the challenge, though the two uses are algebraically identical:
> (do ((n 1 (+ n 1))) (#f) ; A008849
(let* ((x (sigma 1 (* n n n)))
(r (iroot 2 x)))
(when (= x (* r r))
(display n) (display "^3 = ")
(display r) (display "^2") (newline))))
1^3 = 1^2
7^3 = 20^2
751530^3 = 1292054400^2
> (do ((n 1 (+ n 1))) (#f) ; A008850
(let* ((x (sigma 1 (* n n)))
(r (iroot 3 x)))
(when (= x (* r r r))
(display n) (display "^2 = ")
(display r) (display "^3" (newline))))
1^2 = 1^3
43098^2 = 1729^3
Function iroot comes from a previous exercise, and my basic prime-number library, which includes the sigma function, appears on the next page. You can run the program at http://ideone.com/3iqiIH.
If you liked those challenges, here are three more:
1) Find numbers such that the sum of their divisors is a square; for instance, 66.
2) Find squares such that the sum of their divisors is a square; for instance, 81.
3) Find squares such that the sum of their aliquot divisors (divisors of n excluding n) is a square; for instance, 2401.
In Python.
Finding divisors could be more efficient (iterate up through sqrt(n), if i is a divisor, then so is n/i). Also, Python’s range() function doesnt like big numbers, so should be transformed in a while loop.
[…] makes solving the Fermat Exponent problem […]
#include
int main()
{
int i,sum,sq=0,l=0,n;
printf(“Enter the Range\n”);
scanf(“%d”,&n);
for(i=1;i<n;i++)
{
sum=1+i+i*i+i*i*i;
while(sq %d\n”,i,l);
l=1;
}
}
O/P:
Enter the Range
1000
1 -> 2
7 -> 20
EX 2.
#include
int main()
{
int i,sum,cu=0,l=0,n;
printf(“Enter the Range\n”);
scanf(“%d”,&n);
for(i=1;i<n;i++)
{
sum=1+i+i*i;
while(cu %d\n”,l,i);
l=1;
cu=0;
}
}
O/P:
Enter the Range
1000
7 -> 18