Skip to content

Instantly share code, notes, and snippets.

@betrue12
Last active June 24, 2018 14:08
Show Gist options
  • Save betrue12/8dc225135353193b35ae276b884d6db3 to your computer and use it in GitHub Desktop.
Save betrue12/8dc225135353193b35ae276b884d6db3 to your computer and use it in GitHub Desktop.
すぬけ数の差が切り替わるところを列挙する
# https://beta.atcoder.jp/contests/arc099/tasks/arc099_b
# すぬけ数の差は、以下のような数列になっている。
# 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 1000, 1000, 1000, 1000, 1000, 1000, 1000, ...
# この差が変化する境目のすぬけ数を出力すると、その先頭部分にある傾向が見られる。
K = gets.to_i
def digitsum(num)
ret = 0
while num > 0
ret += num % 10
num /= 10
end
ret
end
last = 1
ans = [0, 1]
base = 1
while ans.length < K
if digitsum(last + base) * (last + 10*base) < digitsum(last + 10*base) * (last + base)
# すぬけ数の差が変化したとき、その時の境目となる値と、新しい差の桁数を出力
base *= 10
p [last, base.to_s.length]
end
last += base
ans.push(last)
end
#puts ans
[9, 2]
[99, 3]
[1999, 4]
[29999, 5]
[399999, 6]
[4999999, 7]
[59999999, 8]
[699999999, 9]
[7999999999, 10]
[89999999999, 11]
[999999999999, 12]
[9999999999999, 13]
[109999999999999, 14]
[1199999999999999, 15]
[12999999999999999, 16]
[139999999999999999, 17]
[1499999999999999999, 18]
[15999999999999999999, 19]
[169999999999999999999, 20]
[1799999999999999999999, 21]
[18999999999999999999999, 22]
[199999999999999999999999, 23]
[1999999999999999999999999, 24]
[20999999999999999999999999, 25]
[219999999999999999999999999, 26]
[2299999999999999999999999999, 27]
[23999999999999999999999999999, 28]
[249999999999999999999999999999, 29]
[2599999999999999999999999999999, 30]
[26999999999999999999999999999999, 31]
[279999999999999999999999999999999, 32]
[2899999999999999999999999999999999, 33]
[29999999999999999999999999999999999, 34]
[299999999999999999999999999999999999, 35]
[3099999999999999999999999999999999999, 36]
[31999999999999999999999999999999999999, 37]
[329999999999999999999999999999999999999, 38]
[3399999999999999999999999999999999999999, 39]
[34999999999999999999999999999999999999999, 40]
[359999999999999999999999999999999999999999, 41]
[3699999999999999999999999999999999999999999, 42]
[37999999999999999999999999999999999999999999, 43]
[389999999999999999999999999999999999999999999, 44]
[3999999999999999999999999999999999999999999999, 45]
[39999999999999999999999999999999999999999999999, 46]
[409999999999999999999999999999999999999999999999, 47]
[4199999999999999999999999999999999999999999999999, 48]
[42999999999999999999999999999999999999999999999999, 49]
[439999999999999999999999999999999999999999999999999, 50]
[4499999999999999999999999999999999999999999999999999, 51]
[45999999999999999999999999999999999999999999999999999, 52]
[469999999999999999999999999999999999999999999999999999, 53]
[4799999999999999999999999999999999999999999999999999999, 54]
[48999999999999999999999999999999999999999999999999999999, 55]
[499999999999999999999999999999999999999999999999999999999, 56]
[4999999999999999999999999999999999999999999999999999999999, 57]
[50999999999999999999999999999999999999999999999999999999999, 58]
[519999999999999999999999999999999999999999999999999999999999, 59]
[5299999999999999999999999999999999999999999999999999999999999, 60]
[53999999999999999999999999999999999999999999999999999999999999, 61]
[549999999999999999999999999999999999999999999999999999999999999, 62]
[5599999999999999999999999999999999999999999999999999999999999999, 63]
[56999999999999999999999999999999999999999999999999999999999999999, 64]
[579999999999999999999999999999999999999999999999999999999999999999, 65]
[5899999999999999999999999999999999999999999999999999999999999999999, 66]
[59999999999999999999999999999999999999999999999999999999999999999999, 67]
[599999999999999999999999999999999999999999999999999999999999999999999, 68]
[6099999999999999999999999999999999999999999999999999999999999999999999, 69]
[61999999999999999999999999999999999999999999999999999999999999999999999, 70]
[629999999999999999999999999999999999999999999999999999999999999999999999, 71]
[6399999999999999999999999999999999999999999999999999999999999999999999999, 72]
[64999999999999999999999999999999999999999999999999999999999999999999999999, 73]
[659999999999999999999999999999999999999999999999999999999999999999999999999, 74]
[6699999999999999999999999999999999999999999999999999999999999999999999999999, 75]
[67999999999999999999999999999999999999999999999999999999999999999999999999999, 76]
[689999999999999999999999999999999999999999999999999999999999999999999999999999, 77]
[6999999999999999999999999999999999999999999999999999999999999999999999999999999, 78]
[69999999999999999999999999999999999999999999999999999999999999999999999999999999, 79]
[709999999999999999999999999999999999999999999999999999999999999999999999999999999, 80]
[7199999999999999999999999999999999999999999999999999999999999999999999999999999999, 81]
[72999999999999999999999999999999999999999999999999999999999999999999999999999999999, 82]
[739999999999999999999999999999999999999999999999999999999999999999999999999999999999, 83]
[7499999999999999999999999999999999999999999999999999999999999999999999999999999999999, 84]
[75999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 85]
[769999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 86]
[7799999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 87]
[78999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 88]
[799999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 89]
[7999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 90]
[80999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 91]
[819999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 92]
[8299999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 93]
[83999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 94]
[849999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 95]
[8599999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 96]
[86999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 97]
[879999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 98]
[8899999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 99]
[89999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 100]
[899999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 101]
[9099999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 102]
[91999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 103]
[929999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 104]
[9399999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 105]
[94999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 106]
[959999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 107]
[9699999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 108]
[97999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 109]
[989999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 110]
[9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 111]
[99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 112]
[999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 113]
[10099999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 114]
[101999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 115]
[1029999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 116]
[10399999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 117]
[104999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 118]
[1059999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 119]
[10699999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 120]
[107999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 121]
[1089999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 122]
[10999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 123]
[109999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 124]
[1109999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 125]
[11199999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 126]
[112999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 127]
[1139999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 128]
[11499999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 129]
[115999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 130]
[1169999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 131]
[11799999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 132]
[118999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 133]
[1199999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 134]
[11999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 135]
[120999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 136]
[1219999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 137]
[12299999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 138]
[123999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 139]
[1249999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 140]
[12599999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 141]
[126999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 142]
[1279999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 143]
[12899999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 144]
[129999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 145]
[1299999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 146]
[13099999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 147]
[131999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 148]
[1329999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 149]
[13399999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 150]
[134999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 151]
[1359999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 152]
[13699999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 153]
[137999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 154]
[1389999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 155]
[13999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 156]
[139999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 157]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment