結果

問題 No.1312 Snake Eyes
ユーザー yuruhiyayuruhiya
提出日時 2020-12-13 11:39:07
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 1,072 bytes
コンパイル時間 17,237 ms
コンパイル使用メモリ 256,792 KB
実行使用メモリ 4,536 KB
最終ジャッジ日時 2023-09-13 12:54:17
合計ジャッジ時間 20,800 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,464 KB
testcase_06 AC 2 ms
4,444 KB
testcase_07 AC 2 ms
4,400 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,404 KB
testcase_12 AC 2 ms
4,484 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,408 KB
testcase_17 AC 3 ms
4,436 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 3 ms
4,460 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,488 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 3 ms
4,416 KB
testcase_31 AC 3 ms
4,412 KB
testcase_32 AC 3 ms
4,476 KB
testcase_33 AC 2 ms
4,400 KB
testcase_34 AC 3 ms
4,484 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 3 ms
4,424 KB
testcase_39 AC 4 ms
4,376 KB
testcase_40 AC 4 ms
4,380 KB
testcase_41 AC 4 ms
4,376 KB
testcase_42 AC 3 ms
4,380 KB
testcase_43 AC 4 ms
4,404 KB
testcase_44 AC 3 ms
4,384 KB
testcase_45 AC 3 ms
4,384 KB
testcase_46 AC 3 ms
4,376 KB
testcase_47 AC 4 ms
4,380 KB
testcase_48 AC 43 ms
4,400 KB
testcase_49 AC 39 ms
4,388 KB
testcase_50 AC 32 ms
4,480 KB
testcase_51 AC 18 ms
4,380 KB
testcase_52 AC 48 ms
4,404 KB
testcase_53 AC 36 ms
4,376 KB
testcase_54 AC 43 ms
4,380 KB
testcase_55 AC 22 ms
4,388 KB
testcase_56 AC 28 ms
4,428 KB
testcase_57 AC 28 ms
4,380 KB
testcase_58 AC 37 ms
4,412 KB
testcase_59 AC 15 ms
4,384 KB
testcase_60 AC 28 ms
4,464 KB
testcase_61 AC 48 ms
4,380 KB
testcase_62 AC 20 ms
4,536 KB
testcase_63 AC 3 ms
4,376 KB
testcase_64 AC 4 ms
4,376 KB
testcase_65 AC 8 ms
4,456 KB
testcase_66 AC 2 ms
4,396 KB
testcase_67 AC 3 ms
4,376 KB
testcase_68 AC 4 ms
4,376 KB
testcase_69 AC 2 ms
4,468 KB
testcase_70 AC 40 ms
4,376 KB
testcase_71 AC 24 ms
4,376 KB
testcase_72 AC 4 ms
4,448 KB
testcase_73 AC 3 ms
4,376 KB
testcase_74 AC 2 ms
4,380 KB
testcase_75 AC 3 ms
4,380 KB
testcase_76 AC 48 ms
4,536 KB
testcase_77 AC 49 ms
4,376 KB
testcase_78 AC 48 ms
4,376 KB
testcase_79 AC 37 ms
4,448 KB
testcase_80 AC 49 ms
4,380 KB
testcase_81 AC 48 ms
4,384 KB
testcase_82 AC 49 ms
4,400 KB
testcase_83 AC 48 ms
4,404 KB
testcase_84 AC 49 ms
4,380 KB
testcase_85 AC 45 ms
4,380 KB
testcase_86 AC 42 ms
4,396 KB
testcase_87 AC 24 ms
4,380 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 = Array(Tuple(self, Int32)).new
    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 = Array(self).new
    typeof(self).new(1).upto(self) do |x|
      break if x * x > self
      result << x if self % x == 0
    end
    (0...result.size).reverse_each do |i|
      result << self // result[i] if result[i] * result[i] < self
    end
    result
  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.divisors.each do |a|
  b = n // a - 1
  ans = {ans, b}.min if a < b
end

puts ans
0