Language: C++

#include<bits/stdc++.h>
using namespace std;

long long int n,i,a[110],ans,mod,k,t,j,x;
string s;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>s;n=s.size();cin>>k;
	for (i=1;i<n+1;i++) a[i]=(s[n-i]-'0');
	ans=0;
	if (k==3)
	{
		for (i=3;i<n;i++) ans=ans+((i-1)*(i-2)*9*9*9)/2;
		for (i=1;i<n;i++) for (j=i+1;j<n;j++)
		{
			x=1;
			if (j<n-1) x=x*9*9;else
			{
				x=x*a[j];
				if (i<j-1) x=x*9;else x=x*a[i];
			}
			ans=ans+x+(a[n]-1)*81;
		}
	}
	else if (k==2)
	{
		for (i=2;i<n;i++) ans=ans+(i-1)*81;
		for (i=1;i<n;i++)
		{
			x=1;
			if (i<n-1) x=x*9;else x=x*a[i];
			ans=ans+x+(a[n]-1)*9;
		}
	}
	else ans=(n-1)*9+a[n];
	cout<<ans;
}
#include<bits/stdc++.h>
using namespace std;

long long int n,i,a[110],ans,mod,k,t,j,x;
string s;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>s;n=s.size();cin>>k;
	for (i=1;i<n+1;i++) a[i]=(s[n-i]-'0');
	ans=0;
	if (k==3)
	{
		for (i=3;i<n;i++) ans=ans+((i-1)*(i-2)*9*9*9)/2;
		for (i=1;i<n;i++) for (j=i+1;j<n;j++)
		{
			x=1;
			if (j<n-1) x=x*9*9;else
			{
				x=x*a[j];
				if (i<j-1) x=x*9;else x=x*a[i];
			}
			ans=ans+x+(a[n]-1)*81;
		}
	}
	else if (k==2)
	{
		for (i=2;i<n;i++) ans=ans+(i-1)*81;
		for (i=1;i<n;i++)
		{
			x=1;
			if (i<n-1) x=x*9;else x=x*a[i];
			ans=ans+x+(a[n]-1)*9;
		}
	}
	else ans=(n-1)*9+a[n];
	cout<<ans;
}


Compiler output:
a.cc:46:15: error: redefinition of 'long long int n'
   46 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |               ^
a.cc:4:15: note: 'long long int n' previously declared here
    4 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |               ^
a.cc:46:17: error: redefinition of 'long long int i'
   46 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                 ^
a.cc:4:17: note: 'long long int i' previously declared here
    4 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                 ^
a.cc:46:19: error: redefinition of 'long long int a [110]'
   46 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                   ^
a.cc:4:19: note: 'long long int a [110]' previously declared here
    4 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                   ^
a.cc:46:26: error: redefinition of 'long long int ans'
   46 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                          ^~~
a.cc:4:26: note: 'long long int ans' previously declared here
    4 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                          ^~~
a.cc:46:30: error: redefinition of 'long long int mod'
   46 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                              ^~~
a.cc:4:30: note: 'long long int mod' previously declared here
    4 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                              ^~~
a.cc:46:34: error: redefinition of 'long long int k'
   46 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                                  ^
a.cc:4:34: note: 'long long int k' previously declared here
    4 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                                  ^
a.cc:46:36: error: redefinition of 'long long int t'
   46 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                                    ^
a.cc:4:36: note: 'long long int t' previously declared here
    4 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                                    ^
a.cc:46:38: error: redefinition of 'long long int j'
   46 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                                      ^
a.cc:4:38: note: 'long long int j' previously declared here
    4 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                                      ^
a.cc:46:40: error: redefinition of 'long long int x'
   46 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                                        ^
a.cc:4:40: note: 'long long int x' previously declared here
    4 | long long int n,i,a[110],ans,mod,k,t,j,x;
      |                                        ^
a.cc:47:8: error: redefinition of 'std::string s'
   47 | string s;
      |        ^
a.cc:5:8: note: 'std::string s' previously declared here
    5 | string s;
      |        ^
a.cc:49:8: error: redefinition of 'int main()'
   49 | signed main()
      |        ^~~~
a.cc:7:8: note: 'int main()' previously defined here
    7 | signed main()
      |        ^~~~