
Originally Posted by
beta12 Hi perfect hacker,
phi ( 5186) is just fited into my problem. How do you come up with this answer. Could you please teach me? Thank you very much.
Two ways:
1. Google for Euler Totient function and look through the hits.
2. Write some code to conduct a search:
Define the EulerTotient function
Code:
function EulerTotient(m)
##
## Euler Totient function using the formula from
## Hardy and Wright 5th Ed, p53.
##
## CB 2006
##
ff=factor1(m);..find prime factors and multiplicities
ff=ff(:,1); ..extract the distinct prime factors
ll=length(ff);
prd=m;
..this next bit is for the benefit of causual readers
..the vectorised method is prd=prd*prod(1-1/ff');
for idx=1 to ll
prd=prd*(1-1/ff(idx));
end ..for
rv=round(prd,0);
return rv
endfunction Then a console session to do the search:
Code:
>
>.. load the EulerTotient definition
>
>load "D:\user\temp\EulerTotient.e";
>
>.. test it
>
>EulerTotient(7^2)
42
>
>.. set up a search between lo and hi
>
>function search(lo,hi)
$ rv=[];
$ lst=EulerTotient(lo);
$ for idx=lo+1 to hi
$ nxt=EulerTotient(idx);
$ if nxt==lst
$ nxtnxt=EulerTotient(idx+1);
$ if nxtnxt==nxt
$ rv=rv|idx-1;
$ endif
$ endif
$ lst=nxt;
$ end ..for
$
$ return rv
$endfunction
>
>.. run the search and time it
>
>t=time;search(10,10000),time-t
5186
6.031
> Total time to hack the code ~30m, and to run it 6s.
RonL