Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Casting-out-nines/Java/casting-out-nines.java
Normal file
33
Task/Casting-out-nines/Java/casting-out-nines.java
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import java.util.*;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class CastingOutNines {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(castOut(16, 1, 255));
|
||||
System.out.println(castOut(10, 1, 99));
|
||||
System.out.println(castOut(17, 1, 288));
|
||||
}
|
||||
|
||||
static List<Integer> castOut(int base, int start, int end) {
|
||||
int[] ran = IntStream
|
||||
.range(0, base - 1)
|
||||
.filter(x -> x % (base - 1) == (x * x) % (base - 1))
|
||||
.toArray();
|
||||
|
||||
int x = start / (base - 1);
|
||||
|
||||
List<Integer> result = new ArrayList<>();
|
||||
while (true) {
|
||||
for (int n : ran) {
|
||||
int k = (base - 1) * x + n;
|
||||
if (k < start)
|
||||
continue;
|
||||
if (k > end)
|
||||
return result;
|
||||
result.add(k);
|
||||
}
|
||||
x++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue