Submission #856401


Source Code Expand

Copy
n = gets.to_i
s_str = gets.strip
s = s_str.to_i

slen = s.size

v = 1
12.times {
  kari = (slen/v.to_f).ceil * 10 ** v
  if (kari > s) or (n < 10 ** v)
    break
  end
  v += 1
}
#p v


startv = 10 ** (v - 1) + 1
endv = 10 ** v

def f(b,n)
  if n<b
    return n
  else
    return (f(b,n/b) + n % b)
  end
end

#p startv
#p endv
startv.upto(endv) { |b|
  #puts "b=#{b}"
  if f(b,n) == s
    puts "#{b}"
    exit
  end
}

if (n > 1)
  b = n
  while (b > n - 10)
    #puts "b2=#{b}"
    if f(b,n) == s
      puts "#{b}"
      exit
    end
  end
end
puts "-1"

Submission Info

Submission Time
Task C - Tak and Cards
User cactoid
Language Ruby (2.3.3)
Score 0
Code Size 605 Byte
Status WA
Exec Time 2105 ms
Memory 1788 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 0 / 200 0 / 100
Status
WA × 2
TLE × 2
WA × 5
TLE × 7
WA × 7
TLE × 17
Set Name Test Cases
Sample example_01.txt, example_02.txt, example_03.txt, example_04.txt
Subtask1 example_01.txt, example_02.txt, example_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt
All example_01.txt, example_02.txt, example_03.txt, example_04.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt
Case Name Status Exec Time Memory
example_01.txt TLE 2102 ms 1788 KB
example_02.txt TLE 2105 ms 1788 KB
example_03.txt WA 17 ms 1788 KB
example_04.txt WA 17 ms 1788 KB
subtask1_01.txt TLE 2101 ms 1788 KB
subtask1_02.txt TLE 2105 ms 1788 KB
subtask1_03.txt TLE 2105 ms 1788 KB
subtask1_04.txt WA 17 ms 1788 KB
subtask1_05.txt WA 17 ms 1788 KB
subtask1_06.txt WA 16 ms 1788 KB
subtask1_07.txt WA 17 ms 1788 KB
subtask1_08.txt TLE 2105 ms 1788 KB
subtask1_09.txt TLE 2101 ms 1788 KB
subtask2_01.txt TLE 2101 ms 1788 KB
subtask2_02.txt TLE 2105 ms 1788 KB
subtask2_03.txt TLE 2101 ms 1788 KB
subtask2_04.txt TLE 2101 ms 1788 KB
subtask2_05.txt TLE 2101 ms 1788 KB
subtask2_06.txt WA 17 ms 1788 KB
subtask2_07.txt TLE 2102 ms 1788 KB
subtask2_08.txt TLE 2105 ms 1788 KB
subtask2_09.txt TLE 2101 ms 1788 KB
subtask2_10.txt TLE 2105 ms 1788 KB
subtask2_11.txt TLE 2101 ms 1788 KB