SSL新年欢乐赛暨BPM退役赛 B 签到题

H y p e r l i n k Hyperlink Hyperlink

https://www.luogu.com.cn/problem/U102373?contestId=25686


D e s c r i p t i o n Description Description

给定一个数 n n n,求满足 x + c o u n t ( x ) = n x+count(x)=n x+count(x)=n的所有正整数 x x x

n ≤ 1 0 6 n\leq 10^6 n106


S o l u t i o n Solution Solution

注意到 0 < c o u n t ( x ) < 81 0<count(x)<81 0<count(x)<81,直接往前找81个即可

时间复杂度: O ( 729 ) O(729) O(729)


C o d e Code Code
#include<cctype>
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;LL n,res,a[100010];
inline LL read()
{
	char c;LL d=1,f=0;
	while(c=getchar(),!isdigit(c)) if(c=='-') d=-1;f=(f<<3)+(f<<1)+c-48;
	while(c=getchar(),isdigit(c)) f=(f<<3)+(f<<1)+c-48;
	return d*f;
}
signed main()
{
	n=read();
	for(LL i=max(n-81,1ll);i<=n;i++) 
	{
		LL x=i,y=0;
		while(x) y+=x%10,x/=10;
		if(i+y==n) a[++res]=i;
	}
	printf("%lld\n",res);
	for(register int i=1;i<=res;i++) printf("%lld\n",a[i]);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值