Language: C++

#include <bits/stdc++.h>

using namespace std;
using ll=long long;
using ld=__float128;

#define REP(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,n,m) for(ll i=n; i<(m);i++)
#define eps  1e-5
using mat=vector<vector<ld>>;

mat gauss_jordan(mat A) {
    int n = A.size(), m = A[0].size();
    
    REP(i, n) {
        int piv = i;
        FOR(j, i, n) if (abs((long double)A[j][i]) > abs((long double)A[piv][i])) piv = j;
        swap(A[i], A[piv]);
        if (abs((long double)A[i][i]) < eps) return mat();
        FOR(j, i + 1, m) A[i][j] /= A[i][i];
        A[i][i]=1;
        REP(j, n) {
            if (i != j){
                 FOR(k, i + 1, m) A[j][k] -= A[j][i] * A[i][k];
                 A[j][i]=0;
            }
        }
    }
    /*
    mat x(n);
    REP(i,n)x[i].push_back(A[i][m-1]);
    cout<<"done"<<endl;
    return x;
    */
    return A;
}

mat mul(mat a,mat b){
    int n=a.size(),m=a[0].size(),l=b[0].size();
    assert(m==b.size());
    mat ret(n,vector<ld>(l,0));
    REP(i,n){
        REP(j,l){
            REP(k,m){
                ret[i][j]+=a[i][k]*b[k][j];
            }
        }
    }
    return ret;
}
mat id(ll n){
    mat ret(n,vector<ld>(n,0));
    REP(i,n)ret[i][i]=1;
    return ret;
}
mat pow(mat a,ll n){
  
    if(n==0)return id(a.size());
    mat d=pow(a,n/2);
    mat tmp=mul(d,d);
      cout<<"#"<<n<<endl;
    if(n&1)return mul(tmp,a);
    return tmp;
}

int main(){
    ll s,n,k;
    cin>>s>>n>>k;
    s=abs(s);
    cout<<setprecision(10)<<pow(n,k)<<endl;
    if(n==1){
        if(s%k!=0) cout<<-1<<endl;
        else cout<<(long double)(s)/k<<endl;
        return 0;
    }
    if(s==0){
        cout<<0<<endl;
        return 0;
    }

    vector<vector<ll>> dp(k+1,vector<ll>(n*k+1,0));
    dp[0][0]=1;

    REP(i,k){
        REP(j,n*k+1){
            for(int l=1;l<=n;++l){
                if(j>=l)dp[i+1][j]+=dp[i][j-l];
            }
        }
    }
    REP(i,n*k+1)cout<<dp[k][i]<<" ";
    cout<<endl;
    mat eq(n*k,vector<ld>(n*k+1,0));
    REP(i,n*k) {
        eq[i][n*k]=-pow(n,k);
        eq[i][i]=pow(n,k);
        FOR(j,k,n*k+1) {
            if(j==i+1) continue;
            eq[i][abs(i-(j-1))-1]-=dp[k][j];
        }
    }

    mat ans=gauss_jordan(eq);
 
    vector<ld> e(n*k);
    for(ll i=n*k-1; i>=0; i--) {
        ld tmp=0;
        for(ll j=i+1; j<=n*k; j++) {
            if(j==n*k) {
                tmp-=ans[i][j];
            } else {
                t#include <bits/stdc++.h>

using namespace std;
using ll=long long;
using ld=__float128;

#define REP(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,n,m) for(ll i=n; i<(m);i++)
#define eps  1e-5
using mat=vector<vector<ld>>;

mat gauss_jordan(mat A) {
    int n = A.size(), m = A[0].size();
    
    REP(i, n) {
        int piv = i;
        FOR(j, i, n) if (abs((long double)A[j][i]) > abs((long double)A[piv][i])) piv = j;
        swap(A[i], A[piv]);
        if (abs((long double)A[i][i]) < eps) return mat();
        FOR(j, i + 1, m) A[i][j] /= A[i][i];
        A[i][i]=1;
        REP(j, n) {
            if (i != j){
                 FOR(k, i + 1, m) A[j][k] -= A[j][i] * A[i][k];
                 A[j][i]=0;
            }
        }
    }
    /*
    mat x(n);
    REP(i,n)x[i].push_back(A[i][m-1]);
    cout<<"done"<<endl;
    return x;
    */
    return A;
}

mat mul(mat a,mat b){
    int n=a.size(),m=a[0].size(),l=b[0].size();
    assert(m==b.size());
    mat ret(n,vector<ld>(l,0));
    REP(i,n){
        REP(j,l){
            REP(k,m){
                ret[i][j]+=a[i][k]*b[k][j];
            }
        }
    }
    return ret;
}
mat id(ll n){
    mat ret(n,vector<ld>(n,0));
    REP(i,n)ret[i][i]=1;
    return ret;
}
mat pow(mat a,ll n){
  
    if(n==0)return id(a.size());
    mat d=pow(a,n/2);
    mat tmp=mul(d,d);
      cout<<"#"<<n<<endl;
    if(n&1)return mul(tmp,a);
    return tmp;
}

int main(){
    ll s,n,k;
    cin>>s>>n>>k;
    s=abs(s);
    cout<<setprecision(10)<<pow(n,k)<<endl;
    if(n==1){
        if(s%k!=0) cout<<-1<<endl;
        else cout<<(long double)(s)/k<<endl;
        return 0;
    }
    if(s==0){
        cout<<0<<endl;
        return 0;
    }

    vector<vector<ll>> dp(k+1,vector<ll>(n*k+1,0));
    dp[0][0]=1;

    REP(i,k){
        REP(j,n*k+1){
            for(int l=1;l<=n;++l){
                if(j>=l)dp[i+1][j]+=dp[i][j-l];
            }
        }
    }
    REP(i,n*k+1)cout<<dp[k][i]<<" ";
    cout<<endl;
    mat eq(n*k,vector<ld>(n*k+1,0));
    REP(i,n*k) {
        eq[i][n*k]=-pow(n,k);
        eq[i][i]=pow(n,k);
        FOR(j,k,n*k+1) {
            if(j==i+1) continue;
            eq[i][abs(i-(j-1))-1]-=dp[k][j];
        }
    }

    mat ans=gauss_jordan(eq);
 
    vector<ld> e(n*k);
    for(ll i=n*k-1; i>=0; i--) {
        ld tmp=0;
        for(ll j=i+1; j<=n*k; j++) {
            if(j==n*k) {
                tmp-=ans[i][j];
            } else {
                tmp-=ans[i][j]*e[j];
            }
        }
        e[i]=tmp;
    }
    if(s<=n*k){
        cout<<(long double)e[s-1]<<endl;
        return 0;
    }

    mat c(n*k+1,vector<ld>(n*k+1,0));
    REP(i,n*k-1){
        c[i+1][i]=1;
    }
    c[n*k][n*k]=1;
    c[0][n*k]=1;
    REP(i,n*k){
        c[0][i]=dp[k][i]/pow(n,k);
    }

    mat coe=pow(c,s-n*k);

    mat tmp(n*k+1);

    REP(i,n*k)tmp[i].push_back(e[i]);
    tmp.back().push_back(1);
    mat ret=mul(coe,tmp);
    cout<<setprecision(100)<<(long double)ret[0][0]<<endl;
}
            }
        }
        e[i]=tmp;#include <bits/stdc++.h>

using namespace std;
using ll=long long;
using ld=__float128;

#define REP(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,n,m) for(ll i=n; i<(m);i++)
#define eps  1e-5
using mat=vector<vector<ld>>;

mat gauss_jordan(mat A) {
    int n = A.size(), m = A[0].size();
    
    REP(i, n) {
        int piv = i;
        FOR(j, i, n) if (abs((long double)A[j][i]) > abs((long double)A[piv][i])) piv = j;
        swap(A[i], A[piv]);
        if (abs((long double)A[i][i]) < eps) return mat();
        FOR(j, i + 1, m) A[i][j] /= A[i][i];
        A[i][i]=1;
        REP(j, n) {
            if (i != j){
                 FOR(k, i + 1, m) A[j][k] -= A[j][i] * A[i][k];
                 A[j][i]=0;
            }
        }
    }
    /*
    mat x(n);
    REP(i,n)x[i].push_back(A[i][m-1]);
    cout<<"done"<<endl;
    return x;
    */
    return A;
}

mat mul(mat a,mat b){
    int n=a.size(),m=a[0].size(),l=b[0].size();
    assert(m==b.size());
    mat ret(n,vector<ld>(l,0));
    REP(i,n){
        REP(j,l){
            REP(k,m){
                ret[i][j]+=a[i][k]*b[k][j];
            }
        }
    }
    return ret;
}
mat id(ll n){
    mat ret(n,vector<ld>(n,0));
    REP(i,n)ret[i][i]=1;
    return ret;
}
mat pow(mat a,ll n){
  
    if(n==0)return id(a.size());
    mat d=pow(a,n/2);
    mat tmp=mul(d,d);
      cout<<"#"<<n<<endl;
    if(n&1)return mul(tmp,a);
    return tmp;
}

int main(){
    ll s,n,k;
    cin>>s>>n>>k;
    s=abs(s);
    cout<<setprecision(10)<<pow(n,k)<<endl;
    if(n==1){
        if(s%k!=0) cout<<-1<<endl;
        else cout<<(long double)(s)/k<<endl;
        return 0;
    }
    if(s==0){
        cout<<0<<endl;
        return 0;
    }

    vector<vector<ll>> dp(k+1,vector<ll>(n*k+1,0));
    dp[0][0]=1;

    REP(i,k){
        REP(j,n*k+1){
            for(int l=1;l<=n;++l){
                if(j>=l)dp[i+1][j]+=dp[i][j-l];
            }
        }
    }
    REP(i,n*k+1)cout<<dp[k][i]<<" ";
    cout<<endl;
    mat eq(n*k,vector<ld>(n*k+1,0));
    REP(i,n*k) {
        eq[i][n*k]=-pow(n,k);
        eq[i][i]=pow(n,k);
        FOR(j,k,n*k+1) {
            if(j==i+1) continue;
            eq[i][abs(i-(j-1))-1]-=dp[k][j];
        }
    }

    mat ans=gauss_jordan(eq);
 
    vector<ld> e(n*k);
    for(ll i=n*k-1; i>=0; i--) {
        ld tmp=0;
        for(ll j=i+1; j<=n*k; j++) {
            if(j==n*k) {
                tmp-=ans[i][j];
            } else {
                tmp-=ans[i][j]*e[j];
            }
        }
        e[i]=tmp;
    }
    if(s<=n*k){
        cout<<(long double)e[s-1]<<endl;
        return 0;
    }

    mat c(n*k+1,vector<ld>(n*k+1,0));
    REP(i,n*k-1){
        c[i+1][i]=1;
    }
    c[n*k][n*k]=1;
    c[0][n*k]=1;
    REP(i,n*k){
        c[0][i]=dp[k][i]/pow(n,k);
    }

    mat coe=pow(c,s-n*k);

    mat tmp(n*k+1);

    REP(i,n*k)tmp[i].push_back(e[i]);
    tmp.back().push_back(1);
    mat ret=mul(coe,tmp);
    cout<<setprecision(100)<<(long double)ret[0][0]<<endl;
}
    }
    if(s<=n*k){
        cout<<(long double)e[s-1]<<endl;
        return 0;
    }

    mat c(n*k+1,vector<ld>(n*k+1,0));
    REP(i,n*k-1){
        c[i+1][i]=1;
    }
    c[n*k][n*k]=1;
    c[0][n*k]=1;
    REP(i,n*k){
        c[0][i]=dp[k][i]/pow(n,k);
    }

    mat coe=pow(c,s-n*k);

    mat tmp(n*k+1);

    REP(i,n*k)tmp[i].push_back(e[i]);
    tmp.back().push_back(1);
    mat ret=mul(coe,tmp);
    cout<<setprecision(100)<<(long double)ret[0][0]<<endl;
}


Compiler output:
a.cc:112:18: error: stray '#' in program
  112 |                 t#include <bits/stdc++.h>
      |                  ^
a.cc:254:18: error: stray '#' in program
  254 |         e[i]=tmp;#include <bits/stdc++.h>
      |                  ^
a.cc: In function 'int main()':
a.cc:112:17: error: 't' was not declared in this scope
  112 |                 t#include <bits/stdc++.h>
      |                 ^
a.cc:123:25: error: a function-definition is not allowed here before '{' token
  123 | mat gauss_jordan(mat A) {
      |                         ^
a.cc:149:21: error: a function-definition is not allowed here before '{' token
  149 | mat mul(mat a,mat b){
      |                     ^
a.cc:162:13: error: a function-definition is not allowed here before '{' token
  162 | mat id(ll n){
      |             ^
a.cc:167:20: error: a function-definition is not allowed here before '{' token
  167 | mat pow(mat a,ll n){
      |                    ^
a.cc:177:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  177 | int main(){
      |         ^~
a.cc:177:9: note: remove parentheses to default-initialize a variable
  177 | int main(){
      |         ^~
      |         --
a.cc:177:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:177:11: error: a function-definition is not allowed here before '{' token
  177 | int main(){
      |           ^
a.cc:254:19: error: 'include' was not declared in this scope
  254 |         e[i]=tmp;#include <bits/stdc++.h>
      |                   ^~~~~~~
a.cc:254:28: error: 'bits' was not declared in this scope
  254 |         e[i]=tmp;#include <bits/stdc++.h>
      |                            ^~~~
a.cc:254:33: error: 'stdc' was not declared in this scope; did you mean 'std'?
  254 |         e[i]=tmp;#include <bits/stdc++.h>
      |                                 ^~~~
      |                                 std
a.cc:256:1: error: expected primary-expression before 'using'
  256 | using namespace std;
      | ^~~~~
a.cc:265:25: error: a function-definition is not allowed here before '{' token
  265 | mat gauss_jordan(mat A) {
      |                         ^
a.cc:291:21: error: a function-definition is not allowed here before '{' token
  291 | mat mul(mat a,mat b){
      |                     ^
a.cc:304:13: error: a function-definition is not allowed here before '{' token
  304 | mat id(ll n){
      |             ^
a.cc:309:20: error: a function-definition is not allowed here before '{' token
  309 | mat pow(mat a,ll n){
      |                    ^
a.cc:319:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  319 | int main(){
      |         ^~
a.cc:319:9: note: remove parentheses to default-initialize a variable
  319 | int main(){
      |         ^~
      |         --
a.cc:319:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:319:11: error: a function-definition is not allowed here before '{' token
  319 | int main(){
      |           ^