#!ruby -Ku
def f(x)
@unit.inject('') do |s, u|
x, d = x.divmod(10)
s = u + s if d > 0
s = @num[d] + s if d > 1 || d == 1 && u.empty?
s
end
end
def g(x)
return '零' if x == 0
return '沢山' if x >= 10 ** (4 * @unit2.size)
@unit2.inject('') do |s, u|
x, d = x.divmod(10000)
s = f(d) + u + s if d > 0
s
end
end
@num = %w(零 一 二 三 四 五 六 七 八 九)
@unit = [''] + %w(十 百 千)
@unit2 = [''] + %w(万 億 兆 京 垓 予 穣 溝 澗 正 載 極 恒河沙 阿僧祇 那由多 不可思議 無量大数)
puts g(200030001000047810478801748017480174803748971890478921047801749032174)
IyFydWJ5IC1LdQpkZWYgZih4KQoJQHVuaXQuaW5qZWN0KCcnKSBkbyB8cywgdXwKCQl4LCBkID0geC5kaXZtb2QoMTApCgkJcyA9IHUgKyBzIGlmIGQgPiAwCgkJcyA9IEBudW1bZF0gKyBzIGlmIGQgPiAxIHx8IGQgPT0gMSAmJiB1LmVtcHR5PwoJCXMKCWVuZAplbmQKCmRlZiBnKHgpCglyZXR1cm4gJ+mbticgaWYgeCA9PSAwCglyZXR1cm4gJ+ayouWxsScgaWYgeCA+PSAxMCAqKiAoNCAqIEB1bml0Mi5zaXplKQoJQHVuaXQyLmluamVjdCgnJykgZG8gfHMsIHV8CgkJeCwgZCA9IHguZGl2bW9kKDEwMDAwKQoJCXMgPSBmKGQpICsgdSArIHMgaWYgZCA+IDAKCQlzCgllbmQKZW5kCgpAbnVtID0gJXco6Zu2IOS4gCDkuowg5LiJIOWbmyDkupQg5YWtIOS4gyDlhasg5LmdKQpAdW5pdCA9IFsnJ10gKyAldyjljYEg55m+IOWNgykKQHVuaXQyID0gWycnXSArICV3KOS4hyDlhIQg5YWGIOS6rCDlnpMg5LqIIOepoyDmup0g5r6XIOatoyDovIkg5qW1IOaBkuays+aymSDpmL/lg6fnpYcg6YKj55Sx5aSaIOS4jeWPr+aAneitsCDnhKHph4/lpKfmlbApCgpwdXRzIGcoMjAwMDMwMDAxMDAwMDQ3ODEwNDc4ODAxNzQ4MDE3NDgwMTc0ODAzNzQ4OTcxODkwNDc4OTIxMDQ3ODAxNzQ5MDMyMTc0KQ==