欢迎光临散文网 会员登陆 & 注册

CF 1766A - Extremely Round

2023-07-01 09:36 作者:您是打尖儿还是住店呢  | 我要投稿


Let's call a positive integer extremely round if it has only one non-zero digit. For example, 5000, 4, 1, 10, 200 are extremely round integers; 42, 13, 666, 77, 101 are not.

You are given an integer n. You have to calculate the number of extremely round integers x such that 1≤x≤n.

----------------------------------------------------------------

281 / 5,000

翻译

如果一个正整数只有一位非零数字,我们称其为极舍入。 例如5000、4、1、10、200都是极舍入的整数; 42、13、666、77、101 不是。 给定一个整数 n。 您必须计算满足 1≤x≤n 的极圆整数 x 的数量。

-----------------------------------------------

    其实就是计算整数的数量,如果数字小于10,那就是对应的数字,

如果数字大于10,那么我们就要判断是十位,百位,千位一共有多少,先全部算进去,最后减去最大值的时候,那个位数,比如54321,到万位的时候, 只能到50000,不能再往上走了,

所以这时候就用9减去当前的5,就是4了,sum减去4,就可以了;

下面是代码:



CF 1766A - Extremely Round的评论 (共 条)

分享到微博请遵守国家法律