fork download
  1. while s=gets
  2. h={}
  3. a,b=s.split(" ").map{|e| e.to_i}
  4. a=(a%b)*10
  5. i=0
  6. as=[]
  7. while true
  8. if a<b && a>0 then
  9. while a<b
  10. as<<0
  11. break if h.member?(a)
  12. h[a]=i
  13. a*=10
  14. i+=1
  15. end
  16. end
  17. break if h.member?(a%b)
  18. break if a==0
  19. as<<a/b
  20. a=a%b
  21. break if a==0
  22. h[a]=i
  23. i+=1
  24. a*=10
  25. end
  26. puts as.join("")
  27. if a!=0 then
  28. c=""
  29. as.size.times{|i|
  30. c+=(h[a%b]>i)?" ":"^"
  31. }
  32. puts c
  33. end
  34. end
Success #stdin #stdout 0.01s 6296KB
stdin
1 3
10000 32768
1 11100
1 459550
stdout
3
^
30517578125
0000
 ^^^
0000021760417
 ^^^^^^^^^^^^