Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void main() {
- print('D => N');
- var length = 3000;
- var map = primesMap().take(length).toList();
- for (int d = 0; d < length; d++) {
- var dd = map[d];
- BigInt n = getN(BigInt.from(dd));
- if (n == dd) {
- print('prime here start ----');
- print('$dd => $n ');
- print('prime here end -----');
- } else {
- print('$dd => $n ');
- }
- }
- }
- Iterable<int> primesMap() {
- Iterable<int> oddprms() sync* {
- yield(3); yield(5); // need at least 2 for initialization
- final Map<int, int> bpmap = {9: 6};
- final Iterator<int> bps = oddprms().iterator;
- bps.moveNext(); bps.moveNext(); // skip past 3 to 5
- int bp = bps.current;
- int n = bp;
- int q = bp * bp;
- while (true) {
- n += 2;
- while (n >= q || bpmap.containsKey(n)) {
- if (n >= q) {
- final int inc = bp << 1;
- bpmap[bp * bp + inc] = inc;
- bps.moveNext(); bp = bps.current; q = bp * bp;
- } else {
- final int inc = bpmap.remove(n);
- int next = n + inc;
- while (bpmap.containsKey(next)) {
- next += inc;
- }
- bpmap[next] = inc;
- }
- n += 2;
- }
- yield(n);
- }
- }
- return [2].followedBy(oddprms());
- }
- BigInt getN(BigInt d) {
- int acc = 1;
- while (true) {
- BigInt value = BigInt.parse(acc.toRadixString(2));
- BigInt mod = value % d;
- if (mod == BigInt.zero) {
- return value;
- }
- acc++;
- if (acc > 10000000) {
- print('overflow');
- return d;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement