Skip to content

Instantly share code, notes, and snippets.

@jackliusr
Created August 11, 2014 15:41
Show Gist options
  • Save jackliusr/1cab20fc267b7fdb293a to your computer and use it in GitHub Desktop.
Save jackliusr/1cab20fc267b7fdb293a to your computer and use it in GitHub Desktop.
hackerrank Sherlock and Queries in scala
object Solution {
def main(args: Array[String]) = {
val lines = io.Source.stdin.getLines.toList
val nums = lines.map( l => l.split("\\s+").map(s => s.toLong))
var a = nums(1).toArray
val b = nums(2).toArray
val c = nums(3).toArray
val n = (nums(0)(0) -1).intValue
val m = (nums(0)(1) -1).intValue
val mod = scala.math.pow(10,9).toInt + 7
for(i <- (0 to m ); j<- (0 to n)){
if( (j+ 1) % b(i) == 0)
a(j) = a(j) * c(i) % mod
}
val result= a.map(n => n.toString).mkString(" ")
println(result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment