Für Vorlesungen, bitte die Webseite verwenden. https://flavigny.de/lecture
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

25 linhas
636B

  1. #include "cpp_headers/fcpp.hh"
  2. int main() {
  3. int n = enter_int("Please enter a natural number: ");
  4. // search smallest factor, start with smallest possible: 2
  5. int k=2;
  6. // go until sqrt(n)
  7. while (k <= sqrt(n)) {
  8. // k is factor of n
  9. if (n % k == 0) {
  10. // print out the factor k
  11. print(k);
  12. // reset n to the quotient
  13. n = n / k;
  14. // restart at k=2
  15. k = 2;
  16. } else {
  17. // if k is not a factor, check next one
  18. k++;
  19. }
  20. }
  21. // n is the last prime factor of the original input number
  22. print(n);
  23. }