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
翻譯
如果一個正整數(shù)只有一位非零數(shù)字,我們稱其為極舍入。 例如5000、4、1、10、200都是極舍入的整數(shù); 42、13、666、77、101 不是。 給定一個整數(shù) n。 您必須計算滿足 1≤x≤n 的極圓整數(shù) x 的數(shù)量。
-----------------------------------------------
????其實就是計算整數(shù)的數(shù)量,如果數(shù)字小于10,那就是對應的數(shù)字,
如果數(shù)字大于10,那么我們就要判斷是十位,百位,千位一共有多少,先全部算進去,最后減去最大值的時候,那個位數(shù),比如54321,到萬位的時候, 只能到50000,不能再往上走了,
所以這時候就用9減去當前的5,就是4了,sum減去4,就可以了;
下面是代碼:
標簽: