From e09171467b329da71f934dc1a476f1bf78051f43 Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Mon, 8 Apr 2024 16:02:46 +0200 Subject: [PATCH] inverse_simplicial fix --- miscfunc.cc | 6 ++++-- t.cc | 13 +++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/miscfunc.cc b/miscfunc.cc index cf50929..1c21ac4 100644 --- a/miscfunc.cc +++ b/miscfunc.cc @@ -811,7 +811,7 @@ return stored[d-2][n]; } - +//find largest n such that simplicial(d,n)<=s int inverse_simplicial(int d, unsigned long long s) { if(s==0) return 0; @@ -841,7 +841,9 @@ do x -= dx; } while(std::fabs(dx)>.5); //so usually 2 iterations are enough -return std::floor(x); +int n= std::floor(x); +while(simplicial(d,n)>s) --n; +return n; } #undef SIMPLICIAL_MAXD diff --git a/t.cc b/t.cc index e279a2a..bcdf2ef 100644 --- a/t.cc +++ b/t.cc @@ -3180,10 +3180,15 @@ if(1) { int d,n; cin>>d>>n; -unsigned long long s; -s=simplicial(d,n); -cout <