Largest prime factor P15695


Statement
 

pdf   zip   main.cc   main.c   main.java   main.py

html

Implement an efficient function

int largest_prime_factor(int n);

that returns the largest prime factor of n.

Precondition

It holds n ≥ 2.

Observation You only need to submit the required procedure; your main program will be ignored.

Public test cases
  • Input/Output

    factor_mes_gran(2) → 2
    factor_mes_gran(12) → 3
    factor_mes_gran(23) → 23
    factor_mes_gran(49) → 7
    factor_mes_gran(50) → 5
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C C++ Java Python
    User solutions
    C C++