玄关 除了0其他数都统计对了
查看原帖
玄关 除了0其他数都统计对了
729433
Frilen楼主2024/11/22 16:23
#include <bits/stdc++.h>
using namespace std;
#define ll long long

ll ans[20][15];
ll cnta[15];
ll cntb[15];

ll powmod(int x,int y)
{
	ll ans = 1;
	while(y)
	{
		if(y%2==1)ans *= x;
		x*=x;
		y/=2;
	}
	return ans;
}

ll ge(int x)
{
	ll ans = 0;
	for(int i = 0;i<x;i++)
	{
		ans += powmod(10,i);
	}
	return ans - 1;
}

int main()
{
	for(int i = 0;i<10;i++)ans[0][i]=0;
	for(int i = 1;i<15;i++)
	{
		for(int j = 0;j < 10;j++)
		{
			ans[i][j] = ans[i-1][j]*10 + powmod(10,i-1);
		}
		ll t = ge(i);
		ans[i][0] = ans[i][1]-t;
	}
	ll a,b;
	cin >> a>>b;
	int lenb = 0;
	int lena = 0;
	ll nowb = 0;
	ll nowa = 0;
	while(b)
	{
		ll t = b%10;
		b /= 10;
		if(lenb == 0) for(int i = 0;i<=t;i++)cntb[i]++;
		else
		{
			for(int i = 0;i<10;i++)cntb[i] += t*ans[lenb][i];
			for(int i = 1;i<t;i++)
			{
				cntb[i] += 1ll*powmod(10,lenb);
				cntb[0] += 1ll*powmod(10,lenb-1);
			}
			cntb[t] += nowb+1;
		}
		nowb += t * powmod(10,lenb);
		lenb++;
	}
	a--;
	if(a == 0)cntb[0]--;
	while(a)
	{
		ll t = a%10;
		a /= 10;
		if(lena==0) for(int i = 0;i<=t;i++)cnta[i]++;
		else
		{
			for(int i = 0;i<10;i++)cnta[i] += t*ans[lena][i];
			for(int i = 1;i<t;i++)
			{
				cnta[i] += 1ll*powmod(10,lena);
				cnta[0] += 1ll*powmod(10,lena-1);
			}
			cnta[t] += nowa+1;
		}
		nowa += t*powmod(10,lena);
		lena++;
	}
	for(int i = 0;i<10;i++) cout << cntb[i] - cnta[i]<<' ';
	return 0;
}
2024/11/22 16:23
加载中...