#!/usr/bin/env js91
"use strict";
// 余再帰
function unfold(p, f, g, seed, tail_gen = (x) => []) {
const acc = tail_gen(seed)
while (!(p(seed))) {
acc.push(f(seed));
seed = g(seed);
}
return acc;
}
function Func(num, max) {
return unfold(
(x) => x * (x % 10) > max,
(x) => x,
(x) => x + 1,
num).at(-1) % 10;
}
function main(args) {
if (args.length) {
console.log(`N = ${Func(...args.map((x) => parseInt(x)))}`);
} else {
console.log("wrong number of arguments");
}
}
main(scriptArgs);
IyEvdXNyL2Jpbi9lbnYganM5MQoKInVzZSBzdHJpY3QiOwoKLy8g5L2Z5YaN5biwCmZ1bmN0aW9uIHVuZm9sZChwLCBmLCBnLCBzZWVkLCB0YWlsX2dlbiA9ICh4KSA9PiBbXSkgewogIGNvbnN0IGFjYyA9IHRhaWxfZ2VuKHNlZWQpCiAgd2hpbGUgKCEocChzZWVkKSkpIHsKICAgIGFjYy5wdXNoKGYoc2VlZCkpOwogICAgc2VlZCA9IGcoc2VlZCk7CiAgfQogIHJldHVybiBhY2M7Cn0KCmZ1bmN0aW9uIEZ1bmMobnVtLCBtYXgpIHsKICByZXR1cm4gdW5mb2xkKAogICh4KSA9PiB4ICogKHggJSAxMCkgPiBtYXgsCiAgKHgpID0+IHgsCiAgKHgpID0+IHggKyAxLAogIG51bSkuYXQoLTEpICUgMTA7Cn0KCmZ1bmN0aW9uIG1haW4oYXJncykgewogIGlmIChhcmdzLmxlbmd0aCkgewogICAgY29uc29sZS5sb2coYE4gPSAke0Z1bmMoLi4uYXJncy5tYXAoKHgpID0+IHBhcnNlSW50KHgpKSl9YCk7CiAgfSBlbHNlIHsKICAgIGNvbnNvbGUubG9nKCJ3cm9uZyBudW1iZXIgb2YgYXJndW1lbnRzIik7CiAgfQp9CgptYWluKHNjcmlwdEFyZ3MpOw==