## Comp. science tools on CP 400

2 posts
• Page

**1**of**1**- ghanedan
- Junior Member
**Posts:**2**Joined:**Fri Oct 06, 2017 10:27 am**Calculators:**Casio Afx 2.0, Casio Classpad fx-cp400

### Comp. science tools on CP 400

A reusable program to calculate Euler's totient.

I call this 'PHI function'. See my next post for the same algorithm implemented on a HP50g.

Tested on CP400. Once installed, it can also be called from Main.

Will add more progs on top of this for security and encryption related functions.

Y Guney Hanedan

I call this 'PHI function'. See my next post for the same algorithm implemented on a HP50g.

Tested on CP400. Once installed, it can also be called from Main.

Will add more progs on top of this for security and encryption related functions.

- Code: Select all
`Lbl prompt`

ClrText

'Input A,"Number ?","Euler's totient"

'Comment out if you want to test locally

'Otherwise takes the parameter directly as input

If (A≤0)

Then

Message "Only positive naturals pls !"

Goto prompt

IfEnd

int(A)⇒B

2⇒ctr

B⇒R

While ( ctr^2 ≤ B )

If (mod(B,ctr)=0)

Then

While (mod(B,ctr)=0)

(B/ctr)⇒B

WhileEnd

R×(1-(1/ctr))⇒R

IfEnd

ctr+1⇒ctr

WhileEnd

If (B>1)

Then

R×(1-(1/B))⇒R

IfEnd

NumToStr R,"Fix0",RS

StrJoin "Fast ∮ = ",RS,outp

Print outp

If (R=(A-1))

Then

Print "The input was a prime"

IfEnd

Return R

Y Guney Hanedan

Last edited by ghanedan on Wed Oct 11, 2017 8:49 pm, edited 2 times in total.

- ghanedan
- Junior Member
**Posts:**2**Joined:**Fri Oct 06, 2017 10:27 am**Calculators:**Casio Afx 2.0, Casio Classpad fx-cp400

### Re: Comp. science tools on CP 400

Here the same function ( Euler's totient ) is implemented on an HP50g ( might also be compatible with earlier HPs but NOT with Prime ).

I must note that on initial tests Casio CP400 was a tad faster, and it takes a bit longer ( read twice ) to code in pure RPL.

\<< 'a1' STO

CASE 28 a1 TYPE \=/

THEN 'a1' PURGE "Wrong type. INT req" DOERR

END a1 0. \<=

THEN 'a1' PURGE "Only Positives" DOERR

END

END

2 a1 \-> ctr R

\<<

WHILE ctr 2 ^ a1 \<=

REPEAT

IF a1 ctr MOD 0 SAME

THEN

WHILE a1 ctr MOD 0 SAME

REPEAT a1 ctr / 'a1' STO

END R 1 1 ctr / - * 'R' STO

END 'ctr' INCR

END

IF a1 1 >

THEN R 1 1 a1 / - * 'R' STO

END R R \->NUM

IF a1 1 - R ==

THEN "The number was a prime !"

END

\>> 'a1' PURGE

\>>

Y Guney Hanedan

I must note that on initial tests Casio CP400 was a tad faster, and it takes a bit longer ( read twice ) to code in pure RPL.

\<< 'a1' STO

CASE 28 a1 TYPE \=/

THEN 'a1' PURGE "Wrong type. INT req" DOERR

END a1 0. \<=

THEN 'a1' PURGE "Only Positives" DOERR

END

END

2 a1 \-> ctr R

\<<

WHILE ctr 2 ^ a1 \<=

REPEAT

IF a1 ctr MOD 0 SAME

THEN

WHILE a1 ctr MOD 0 SAME

REPEAT a1 ctr / 'a1' STO

END R 1 1 ctr / - * 'R' STO

END 'ctr' INCR

END

IF a1 1 >

THEN R 1 1 a1 / - * 'R' STO

END R R \->NUM

IF a1 1 - R ==

THEN "The number was a prime !"

END

\>> 'a1' PURGE

\>>

Y Guney Hanedan

2 posts
• Page

**1**of**1**### Who is online

Users browsing this forum: No registered users and 6 guests