結果

問題 No.1312 Snake Eyes
ユーザー yuruhiyayuruhiya
提出日時 2020-12-13 11:56:02
言語 Crystal
(1.11.2)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,176 bytes
コンパイル時間 15,757 ms
コンパイル使用メモリ 296,040 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-07 18:15:12
合計ジャッジ時間 13,595 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 4 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 3 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 3 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 42 ms
5,376 KB
testcase_49 AC 40 ms
5,376 KB
testcase_50 AC 31 ms
5,376 KB
testcase_51 AC 17 ms
5,376 KB
testcase_52 AC 47 ms
5,376 KB
testcase_53 AC 36 ms
5,376 KB
testcase_54 AC 40 ms
5,376 KB
testcase_55 AC 21 ms
5,376 KB
testcase_56 AC 27 ms
5,376 KB
testcase_57 AC 28 ms
5,376 KB
testcase_58 AC 34 ms
5,376 KB
testcase_59 AC 14 ms
5,376 KB
testcase_60 AC 27 ms
5,376 KB
testcase_61 AC 45 ms
5,376 KB
testcase_62 AC 19 ms
5,376 KB
testcase_63 AC 2 ms
5,376 KB
testcase_64 AC 3 ms
5,376 KB
testcase_65 AC 7 ms
5,376 KB
testcase_66 AC 2 ms
5,376 KB
testcase_67 AC 1 ms
5,376 KB
testcase_68 AC 4 ms
5,376 KB
testcase_69 AC 1 ms
5,376 KB
testcase_70 AC 39 ms
5,376 KB
testcase_71 AC 24 ms
5,376 KB
testcase_72 AC 3 ms
5,376 KB
testcase_73 AC 1 ms
5,376 KB
testcase_74 AC 2 ms
5,376 KB
testcase_75 AC 2 ms
5,376 KB
testcase_76 AC 47 ms
5,376 KB
testcase_77 AC 49 ms
5,376 KB
testcase_78 AC 47 ms
5,376 KB
testcase_79 AC 35 ms
5,376 KB
testcase_80 AC 47 ms
5,376 KB
testcase_81 AC 48 ms
5,376 KB
testcase_82 AC 47 ms
5,376 KB
testcase_83 AC 45 ms
5,376 KB
testcase_84 AC 46 ms
5,376 KB
testcase_85 AC 43 ms
5,376 KB
testcase_86 AC 42 ms
5,376 KB
testcase_87 AC 24 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end

class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end

struct Int
  def prime_factor : Array(Tuple(self, Int32))
    result = [] of Tuple(self, Int32)
    n = self
    typeof(self).new(2).upto(Math.sqrt(self).ceil) do |x|
      count = 0
      while n % x == 0
        n //= x
        count += 1
      end
      result << {x, count} if count > 0
    end
    result << {n, 1} if n != 1
    result
  end

  def divisors : Array(self)
    result = [] of self
    each_divisor do |d|
      result << d
    end
    result
  end

  def each_divisor(&)
    tmp = [] of self
    typeof(self).new(1).upto(self) do |x|
      break if x * x > self
      if self % x == 0
        yield x
        tmp << x
      end
    end
    (0...tmp.size).reverse_each do |i|
      yield self // tmp[i] if tmp[i] * tmp[i] < self
    end
  end
end

n = read_line.to_i64
ans = n + 1
(2i64..Math.sqrt(n).to_i64).each do |r|
  val = 1i64
  while val <= n
    ans = {ans, r}.min if n % val == 0 && n // val < r
    val = val * r + 1
  end
end

n.each_divisor do |a|
  b = n // a - 1
  ans = {ans, b}.min if a < b
end

puts ans
0