16
1
Given a positive integer N
, output the number of pairs of integers 0 <= a <= b < 2**N
such that a*b >= 2**N
.
Rules
- You may assume that
N
is less than or equal to the maximum bit width for integers in your language (e.g. for C,N
will not exceed32
or64
, depending on the architecture of the machine). If your language is capable of handling arbitrary-width integers, then there is no upper bound onN
.
Test Cases
1 0
2 3
3 19
4 96
5 437
6 1876
7 7804
8 31904
9 129170
10 520135
11 2088143
12 8369175
13 33512744
14 134128704
15 536681553
16 2147082274
Note: I'm working on generating larger test cases now. My brute force approach is really slow. – Mego – 2017-06-08T05:44:14.667
@user202729 You're duplicating some pairs by not following the
a <= b
condition. – Mego – 2017-06-08T05:52:53.8471Some more testcases:
{0, 3, 19, 96, 437, 1876, 7804, 31904, 129170, 520135, 2088143, 8369175, 33512744, 134128704, 536681553, 2147082274, 8589086503, 34357951447}
– user202729 – 2017-06-08T06:03:23.2031Isn't there likely to be closed form formula for this problem? I must have missed something. – None – 2017-06-08T06:30:16.287
@Lembik There probably is. I don't know what it is, though. – Mego – 2017-06-08T06:31:00.593
I take it back. The answer is approximately
(1/2)M^2 - M - (1/2)M ln(M)
whereM = 2**N
. – None – 2017-06-08T07:11:38.9231
Closely related: https://en.wikipedia.org/wiki/Divisor_summatory_function. There is no closed form known.
– orlp – 2017-06-08T07:32:46.440Does ordering matter? If 2 and 3 work for example, does that count as one or two? Because that could be expressed by a=2,b=3 or a=3,b=2 – Cyoce – 2017-06-08T08:26:37.797
@Cyoce Because of the
0 <= a <= b < 2**N
requirement, only(2, 3)
would be considered. – Mego – 2017-06-08T08:27:26.670@Mego right. Didn't read that part I guess – Cyoce – 2017-06-08T08:27:57.617
@Lembik: If there is, it isn't in OEIS. This was posted to math.se where there is an approximate solution but nobody has made an exact one.
– Ross Millikan – 2017-06-08T17:56:15.860@RossMillikan Yes. Hence "I take it back." above :) The
2^{N/3}
solution is pretty cool! Someone should implement that here. – None – 2017-06-08T18:02:11.427