paranid5

10 28.11

Nov 28th, 2021 (edited)
702
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extension on int {
  2.   List<int> getDivs(final bool Function(int) predicate) {
  3.     final divs = List<int>.empty(growable: true);
  4.     for (int i = 1; i * i <= this; i++) {
  5.       if (this % i == 0) {
  6.         if (predicate(i)) {
  7.           divs.add(i);
  8.         }
  9.  
  10.         if (i * i < this && predicate(this ~/ i)) {
  11.           divs.add(this ~/ i);
  12.         }
  13.       }
  14.     }
  15.  
  16.     return divs;
  17.   }
  18.  
  19.   bool get isSimple {
  20.     for (int i = 2; i * i <= this; i++) {
  21.       if (this % i == 0) {
  22.         return false;
  23.       }
  24.     }
  25.  
  26.     return true;
  27.   }
  28. }
  29.  
  30. extension on List<int> {
  31.   List<int> sortAndGet() {
  32.     sort();
  33.     return this;
  34.   }
  35. }
  36.  
  37. extension IntIterableExt on Iterable<int> {
  38.   static Iterable<int> createRange(final int startInclusive, final int endExclusive) =>
  39.       Iterable.generate(endExclusive - startInclusive + 1, (x) => x + startInclusive);
  40. }
  41.  
  42. extension IterableExt<T> on Iterable<T> {
  43.   Iterable<T> withStep(final int step) {
  44.     final list = List<T>.empty(growable: true);
  45.     final thisList = toList();
  46.  
  47.     for (int i = 0; i < length; i += step) {
  48.       list.add(thisList[i]);
  49.     }
  50.  
  51.     return list;
  52.   }
  53.  
  54.   void forEachIndexed(void Function(int, T) action) {
  55.     final iter = iterator;
  56.  
  57.     for (int i = 0; i < length; i++) {
  58.       iter.moveNext();
  59.       action(i, iter.current);
  60.     }
  61.   }
  62. }
  63.  
  64. void main(final List<String> arguments) =>
  65.     IntIterableExt.createRange(2532000, 2532160)
  66.         .where((element) => element.isSimple)
  67.         .withStep(3)
  68.         .forEachIndexed((ind, e) => print('${(ind + 1) + ind * 2} $e'));
  69.  
RAW Paste Data