line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2011, 2012, 2013, 2014 Kevin Ryde |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# This file is part of Math-NumSeq. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Math-NumSeq is free software; you can redistribute it and/or modify |
6
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by the |
7
|
|
|
|
|
|
|
# Free Software Foundation; either version 3, or (at your option) any later |
8
|
|
|
|
|
|
|
# version. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Math-NumSeq is distributed in the hope that it will be useful, but |
11
|
|
|
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
12
|
|
|
|
|
|
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
13
|
|
|
|
|
|
|
# for more details. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License along |
16
|
|
|
|
|
|
|
# with Math-NumSeq. If not, see . |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Math::NumSeq::CullenNumbers; |
19
|
1
|
|
|
1
|
|
3452
|
use 5.004; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
55
|
|
20
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
61
|
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
6
|
use vars '$VERSION', '@ISA'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
76
|
|
23
|
|
|
|
|
|
|
$VERSION = 71; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
7
|
use Math::NumSeq; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
70
|
|
26
|
|
|
|
|
|
|
@ISA = ('Math::NumSeq'); |
27
|
|
|
|
|
|
|
*_is_infinite = \&Math::NumSeq::_is_infinite; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# uncomment this to run the ### lines |
30
|
|
|
|
|
|
|
#use Smart::Comments; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# use constant name => Math::NumSeq::__('Cullen Numbers'); |
34
|
1
|
|
|
1
|
|
6
|
use constant description => Math::NumSeq::__('Cullen numbers n*2^n+1.'); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
69
|
|
35
|
1
|
|
|
1
|
|
6
|
use constant i_start => 0; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
36
|
1
|
|
|
1
|
|
6
|
use constant values_min => 1; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
37
|
1
|
|
|
1
|
|
4
|
use constant characteristic_increasing => 1; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
38
|
1
|
|
|
1
|
|
5
|
use constant characteristic_integer => 1; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
47
|
|
39
|
1
|
|
|
1
|
|
5
|
use constant oeis_anum => 'A002064'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
576
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# pow*i+1 |
42
|
|
|
|
|
|
|
my $uv_i_limit = do { |
43
|
|
|
|
|
|
|
my $max = ~0; |
44
|
|
|
|
|
|
|
my $limit = 1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
for (my $i = 1; $i < 1000; $i++) { |
47
|
|
|
|
|
|
|
if ($i <= ($max-1) >> $i) { |
48
|
|
|
|
|
|
|
$limit = $i; |
49
|
|
|
|
|
|
|
} else { |
50
|
|
|
|
|
|
|
last; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
### max : $max |
55
|
|
|
|
|
|
|
### cullen: (1<<$limit)*$limit+1 |
56
|
|
|
|
|
|
|
### assert: $limit*(1<<$limit)+1 <= $max |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$limit |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
### $uv_i_limit |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# or maybe ... |
63
|
|
|
|
|
|
|
# (i+1)*2^(i+1) + 1 |
64
|
|
|
|
|
|
|
# = 2*(i+1)*2^i + 1 |
65
|
|
|
|
|
|
|
# = (2i+2)*2^i + 1 |
66
|
|
|
|
|
|
|
# = 2i*2^i + 2*2^i + 1 |
67
|
|
|
|
|
|
|
# = 2(i*2^i + 1) -2 + 2*2^i + 1 |
68
|
|
|
|
|
|
|
# = 2(i*2^i + 1) + 2*2^i - 1 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub rewind { |
71
|
3
|
|
|
3
|
1
|
495
|
my ($self) = @_; |
72
|
3
|
|
|
|
|
23
|
my $i = $self->{'i'} = $self->i_start; |
73
|
3
|
|
|
|
|
14
|
$self->{'power'} = 2 ** $i; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
sub _UNTESTED__seek_to_i { |
76
|
0
|
|
|
0
|
|
0
|
my ($self, $i) = @_; |
77
|
0
|
|
|
|
|
0
|
$self->{'i'} = $i; |
78
|
0
|
0
|
|
|
|
0
|
if ($i >= $uv_i_limit) { |
79
|
0
|
|
|
|
|
0
|
$i = Math::NumSeq::_to_bigint($i); |
80
|
|
|
|
|
|
|
} |
81
|
0
|
|
|
|
|
0
|
$self->{'power'} = 2 ** $i; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
sub _UNTESTED__seek_to_value { |
84
|
0
|
|
|
0
|
|
0
|
my ($self, $value) = @_; |
85
|
0
|
|
|
|
|
0
|
$self->seek_to_i($self->value_to_i_ceil($value)); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
sub next { |
88
|
20
|
|
|
20
|
1
|
657
|
my ($self) = @_; |
89
|
20
|
|
|
|
|
28
|
my $i = $self->{'i'}++; |
90
|
20
|
50
|
|
|
|
34
|
if ($i == $uv_i_limit) { |
91
|
0
|
|
|
|
|
0
|
$self->{'power'} = Math::NumSeq::_to_bigint($self->{'power'}); |
92
|
|
|
|
|
|
|
} |
93
|
20
|
|
|
|
|
29
|
my $value = $self->{'power'}*$i + 1; |
94
|
20
|
|
|
|
|
23
|
$self->{'power'} *= 2; |
95
|
20
|
|
|
|
|
44
|
return ($i, $value); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub ith { |
99
|
33
|
|
|
33
|
1
|
99
|
my ($self, $i) = @_; |
100
|
33
|
|
|
|
|
100
|
return $i * 2**$i + 1; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
sub pred { |
103
|
1803
|
|
|
1803
|
1
|
7719
|
my ($self, $value) = @_; |
104
|
|
|
|
|
|
|
### CullenNumbers pred(): $value |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
{ |
107
|
1803
|
|
|
|
|
1848
|
my $int = int($value); |
|
1803
|
|
|
|
|
2079
|
|
108
|
1803
|
100
|
|
|
|
3176
|
if ($value != $int) { return 0; } |
|
896
|
|
|
|
|
1661
|
|
109
|
907
|
|
|
|
|
1096
|
$value = $int; |
110
|
|
|
|
|
|
|
} |
111
|
907
|
100
|
66
|
|
|
3145
|
unless ($value >= 1 |
112
|
|
|
|
|
|
|
&& ($value % 2) == 1) { |
113
|
448
|
|
|
|
|
847
|
return 0; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
459
|
|
|
|
|
474
|
$value -= 1; # now seeking $value == $exp * 2**$exp |
117
|
|
|
|
|
|
|
|
118
|
459
|
50
|
|
|
|
959
|
if (_is_infinite($value)) { |
119
|
0
|
|
|
|
|
0
|
return 0; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
459
|
|
|
|
|
610
|
my $exp = 0; |
123
|
459
|
|
|
|
|
529
|
for (;;) { |
124
|
1384
|
100
|
100
|
|
|
4700
|
if ($value <= $exp || $value % 2) { |
125
|
459
|
|
|
|
|
1058
|
return ($value == $exp); |
126
|
|
|
|
|
|
|
} |
127
|
925
|
|
|
|
|
1147
|
$value = int($value/2); |
128
|
925
|
|
|
|
|
906
|
$exp++; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
1
|
|
|
1
|
|
1891
|
use Math::NumSeq::WoodallNumbers; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
79
|
|
133
|
|
|
|
|
|
|
*value_to_i_estimate = \&Math::NumSeq::WoodallNumbers::value_to_i_estimate; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |
136
|
|
|
|
|
|
|
__END__ |