also, a slight tweak: static vector<unsigned long long> a(n);//unsigned long long a[n] dosent work
this is also interesting. Its an approximation. It runs in about 1 nanosecond. Its not quite right, but I am thinking if someone put some energy into it, you could find a direct computation of your answer.
int main()
{
unsignedlonglong t=2;
for(unsignedlonglong i = 1; i < 25; i++)
{
t = t* min((3.0+ 0.166666666*i), 3.8);
cout << t << endl;
}
output of approximate vs actual:
C:\c>a
C:\c>a
1 6 6
2 19 20
3 66 70
4 241 252
5 915 924
6 3476 3432
7 13208 12870
8 50190 48620
9 190721 184756
10 724739 705432
11 2754008 2704156
12 10465230 10400600
13 39767873 40116600
14 151117917 155117520
15 574248084 601080390
16 2182142719 2333606220
and just the approximation out to 30: (warning, by here it has hit the 3.8 min in the
equation and it may not be correct this far out).
20 483427915062
21 1837026077235
22 6980699093492
23 26526656555269
24 100801294910022
25 383044920658083
26 1455570698500715
27 5531168654302716
28 21018440886350319
29 79870075368131212
int main()
{
unsigned long long t=2;
//unsigned long long p=2;
double pd = 0;
int den = 3;
for(unsigned long long i = 3; i < 25; i++)
{
pd += 1.0/den;
den += i;
t *= (3.0+pd);
if( i == 17) t = 601080390; //catchup/manual correction (yea, i cheated!)
cout << t << endl;
}
}
That is about the best I could do with it. If you look at your function's answers divided by the previous one, you get the 3,3.33, etc sequence. Looking at the difference between those, its 3.0 + a running sum (1/3 + 1/6 + 1/10 etc). The code is doing THAT but its still not exact, either floating point errors or these ratios are close but not exact or something of that nature. Anyone see anything I did wrong or have a better way to compute it??
Thank you for your reply.
Do you remember I was telling about that there is two anomal points.
So take a look
2., 3., 3.33333, 3.5, 3.6, 3.66667, 3.71429, 3.75, 3.77778, 3.8, \
3.81818, 3.83333, 3.84615, 3.85714, 2.86957, 5.22145, 3.88235, \
3.88889, 3.89474, 3.9, 3.90476
That's why my mathematica cant find a formula because of these two points.
Unfortunately, these two numbers spoil all the picture. Perhaps, there is some further anomal points far away.
I remember now :( My list did not generate those 2 values. Are you sure about them?! I got 3.85714
3.86667
3.875
I also swapped to u64 bit ints. Maybe something happened size-wise?
Well, at least the loop-skip tweak should shave off some major time. Do you agree with it? It seems to be exact?
its also really about how much of an approximation you can tolerate.
601080390/155117520= 5.22
Oh my God. @lastchance. I dont believe my eyes. How is this possible.
I dont fully understand how it gets the result so quickly.
Would you mind to give some comments? Thanks in advance.
I see it uses some array operations without the matrix generated.
your post hadn't come through yet, had to refresh.
v15/14 from lastchance's list is 3.8x ... there isnt any anomaly, not that it matters if theres a quick algorithm for it.
you are correct. but from lastchance's values, 14 and 15 are.. they are not the same values. And I got the same as he did. ... where did 11511 come from, vs 15511.
40116600
v15 = 155117520 this is why you see an anomaly, your #15 is wrong so 14/15 and 15/16 had a malfunction.
There isnt much point now, but I am firmly convinced there is a sequence behind this thing that would get it equally as fast as LC's code, though dealing with roundoff errors is going to make it an approximation vs his very clean exact answer. I got 27 = 2265962932982288 vs 1946939425648112 (194 vs 226, not great, but ballpark -- 15% error is starting to get too much). I am probably going to try to drive the error down if I can, just for fun at this point.
Well its no news to anyone here but I am an idiot, I was off by one in the sequence lol. It still has roundoff but its tiny and about what we expect now that the multiplier is in sync with the running value instead of shifted :)
so here it is as a sequence, single loop and Im done with it. (I got this yesterday, just now getting back to posting it though). And yes, I know, but it was bugging me that it wasn't right before.
lastchance which tool did you use for that picture?
It's just word-processed in Microsoft Word, saved as a PDF, re-opened in the GIMP, cropped to size, exported as a PNG file. Nothing's straightforward in this world!
Took a lot longer than my scribbled original version on the back of my telephone bill, which I actually used to code from.
Microsoft Word ... PDF ... GIMP ... cropped ... PNG
LibreOffice provides an “export as png” option, and you can choose the final dimensions in the simple exporting mask (with the utmost respect for Ms Word, of course).