0 ~ 9 までの数字をすべて使った割り算の筆算のうち,「割られる数」が最も小さくなるような場合を求め,その式を答えよ。
なお、「割られる数」と「割る数」はともに正の整数とし,整数の商と余りを求めるものとする。
calc = function(numerator, denominator) {
func = function(n) {
return(as.numeric(unlist(strsplit(as.character(n), ""))))
}
numerator.a = func(numerator)
denominator.a = func(denominator)
ans = numerator%/%denominator
ans.length = nchar(as.character(ans))
numerator.length = nchar(numerator)
i = 1
j = 0
num = numerator.a[i]
prod = num.list = vector("list", ans.length)
for (k in seq_len(ans.length)) {
if (num == 0)
break
while (denominator > num) {
i = i + 1
if (i > numerator.length)
break
num = 10 * num + numerator.a[i]
}
j = j + 1
num.list[[j]] = func(num)
ans[j] = num%/%denominator
prod[[k]] = func(denominator * ans[j])
num = num%%denominator
}
ans = c(ans, denominator.a, func(num), unlist(prod), unlist(num.list))
return(length(table(ans)) == 10)
}
found = FALSE
for (i in 1:1000) {
for (j in 1:i) {
if (calc(i, j)) {
cat(i, "/", j, "\n")
found = TRUE
break
}
}
if (found)
break
}
190 ÷ 78 かな。