$q = 2 # This should be your qustion data = File.open "DATA"+$q.to_s+".txt", "r" File.delete("OUT"+$q.to_s+".txt") if(File.exist?("OUT"+$q.to_s+".txt")) def output str f = File.open("OUT"+$q.to_s+".txt", "a") f.puts(str) f.close end def processInput number counter = 0 for i in 1...number+1 for j in i...number+1 puts i.to_s + " " + j.to_s if i*j <= number counter += 1 else break end end end output(counter) counter end 5.times{ |i| puts "Test case "+(i+1).to_s puts processInput data.gets.to_i }