codeforces 1553A

题目要求计算在1到n之间满足S(x+1)<S(x)条件的整数x的数量,其中S(x)表示x的各位数字之和。解决方案提到对于每10个数中有1个数满足有趣数的定义,即除以10的余数为9的数。输出每个测试用例中满足条件的有趣数的个数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Digits Sum

Let’s define S(x) to be the sum of digits of number x written in decimal system. For example, S(5)=5, S(10)=1, S(322)=7.

We will call an integer x interesting if S(x+1)<S(x). In each test you
will be given one integer n. Your task is to calculate the number of
integers x such that 1≤x≤n and x is interesting.

Input The first line contains one integer t (1≤t≤1000) — number of
test cases.

Then t lines follow, the i-th line contains one integer n (1≤n≤109)
for the i-th test case.

Output Print t integers, the i-th should be the answer for the i-th
test case.

题意:s(n)表示的是当前数所有位之和,S(322)=3+2+2=7,让你求当前数字内s(n+1)<s(n)的情况的个数

个人思路:这道题仔细看题的例子就会发现很多数都是/10后得到正确答案,这的确是思路,但是当时没考虑个位为9这个特别的例子

思路:我们先来1-10中间的,能被称为有趣数的也只有s(9) (s(9)=9, s(10)=1),
然后在1-20答案为s(9),s(19)也就是说每10个中就只有一个数能满足

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值