add ipi6
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
#include "cpp_headers/fcpp.hh"
|
||||
|
||||
int main() {
|
||||
int n = enter_int("Please enter a natural number: ");
|
||||
// search smallest factor, start with smallest possible: 2
|
||||
int k=2;
|
||||
// go until sqrt(n)
|
||||
while (k <= sqrt(n)) {
|
||||
printf("searching for dividers for %d, checking %d\n", n, k);
|
||||
// k is factor of n
|
||||
if (n % k == 0) {
|
||||
// print out the factor k
|
||||
print(k);
|
||||
// reset n to the quotient
|
||||
n = n / k;
|
||||
printf("found %d, setting n=%d\n", k, n);
|
||||
// restart at k=2
|
||||
k = 2;
|
||||
} else {
|
||||
// if k is not a factor, check next one
|
||||
k++;
|
||||
}
|
||||
}
|
||||
// n is the last prime factor of the original input number
|
||||
print(n);
|
||||
}
|
||||
Reference in New Issue
Block a user