[Ruby] O(k)
\n# @param {Integer} k\n# @return {Integer}\ndef smallest_repunit_div_by_k(k)\n  return -1 unless [1, 3, 7, 9].include?(k%10)\n  \n  mod = 0\n  mod_set = Set.ne
```\n# @param {Integer} k\n# @return {Integer}\ndef smallest_repunit_div_by_k(k)\n  return -1 unless [1, 3, 7, 9].include?(k%10)\n  \n  mod = 0\n  mod_set = Set.new\n  \n  (1..k).each do |length|\n    mod = (10*mod + 1)%k\n\n    return length if mod == 0\n    return -1 if mod_set.include?(mod)\n\n    mod_set << mod\n  end\n  \n  -1\nend\n```
['Ruby']