Here is the algorithm:
Initialize and .
While : if divides , set and divide by . Otherwise, increment .
If after the loop, then itself is the largest prime factor.
Return .
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Step by step approach
Here is the algorithm:
Initialize and .
While : if divides , set and divide by . Otherwise, increment .
If after the loop, then itself is the largest prime factor.
Return .