首页综合 > 正文

CF 1766A - Extremely Round

2023-07-01 09:23:53来源:哔哩哔哩


(资料图片仅供参考)

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,就可以了;

下面是代码:

关键词:

便民

点击加载更多

频道推荐

  • 服饰
  • 时尚
  • 物流
  • 灯饰
  • 养老
let oimg = document.querySelectorAll('img'); for(var i=0;i