Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
37
Task/Almost-prime/Processing/almost-prime.processing
Normal file
37
Task/Almost-prime/Processing/almost-prime.processing
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
void setup() {
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
int count = 0;
|
||||
print("k = " + i + ": ");
|
||||
int n = 2;
|
||||
while (count < 10) {
|
||||
if (isAlmostPrime(i, n)) {
|
||||
count++;
|
||||
print(n + " ");
|
||||
}
|
||||
n++;
|
||||
}
|
||||
println();
|
||||
}
|
||||
}
|
||||
|
||||
boolean isAlmostPrime(int k, int n) {
|
||||
if (countPrimeFactors(n) == k) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int countPrimeFactors(int n) {
|
||||
int count = 0;
|
||||
int i = 2;
|
||||
while (n > 1) {
|
||||
if (n % i == 0) {
|
||||
n /= i;
|
||||
count++;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue