結果
問題 | No.251 大きな桁の復習問題(1) |
ユーザー |
|
提出日時 | 2015-07-25 06:51:29 |
言語 | Scala(Beta) (3.6.2) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 6,955 bytes |
コンパイル時間 | 6,744 ms |
コンパイル使用メモリ | 232,416 KB |
最終ジャッジ日時 | 2024-11-14 19:07:17 |
合計ジャッジ時間 | 7,633 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
[31m[31m-- [E100] Syntax Error: Main.scala:43:14 ---------------------------------------[0m[0m [31m43 |[0m [33mval[0m n,m = nextBigInt [31m[31m |[0m ^^^^^^^^^^[0m [31m |[0m [33mmethod[0m [35mnextBigInt[0m in [33mclass[0m [35mMyConsole[0m must be called with () argument [31m |[0m [31m |[0m longer explanation available when compiling with `-explain` [31m[31m-- [E100] Syntax Error: Main.scala:83:70 ---------------------------------------[0m[0m [31m83 |[0m [33mdef[0m [36mreadIntVector[0m() : [35mVector[0m[[35mInt[0m] = parseLineToVector(() => nextInt) [31m[31m |[0m ^^^^^^^[0m [31m |[0m [33mmethod[0m [35mnextInt[0m in [33mclass[0m [35mMyConsole[0m must be called with () argument [31m |[0m [31m |[0m longer explanation available when compiling with `-explain` [31m[31m-- [E100] Syntax Error: Main.scala:84:70 ---------------------------------------[0m[0m [31m84 |[0m [33mdef[0m [36mreadLongVector[0m() : [35mVector[0m[[35mLong[0m] = parseLineToVector(() => nextLong) [31m[31m |[0m ^^^^^^^^[0m [31m |[0m [33mmethod[0m [35mnextLong[0m in [33mclass[0m [35mMyConsole[0m must be called with () argument [31m |[0m [31m |[0m longer explanation available when compiling with `-explain` [31m[31m-- [E100] Syntax Error: Main.scala:85:70 ---------------------------------------[0m[0m [31m85 |[0m [33mdef[0m [36mreadStringVector[0m() : [35mVector[0m[[35mString[0m] = parseLineToVector(() => nextString) [31m[31m |[0m ^^^^^^^^^^[0m [31m |[0m [33mmethod[0m [35mnextString[0m in [33mclass[0m [35mMyConsole[0m must be called with () argument [31m |[0m [31m |[0m longer explanation available when comp
ソースコード
import scala.annotation.tailrecimport net.pushl.io.MyConsole// Document: http://www.scala-lang.org/api/current/#package// -----------------------------------------------------------------------------class Solver(val stdio: MyConsole){import stdio._ // shadow Console.~// def pow(x: BigInt, n: BigInt, mod: Long) : BigInt = {// if(n == 0)// BigInt(1)// else{// val t = pow((x*x)%mod,n/2,mod)// if(n % 2 == 1) (t*x) % mod// else t % mod// }// }// def pow(x: Long, n: BigInt, mod: Long) : Long = {// if(n == 0)// 1// else{// val t = pow((x*x)%mod,n/2,mod)// if(n % 2 == 1) (t*x) % mod// else t % mod// }// }// def pow(x: Long, n: BigInt, mod: Long) : Long = {// @tailrec// def powi(x: Long, n: BigInt, res: Long) : Long = {// if(n == 0)// res// else if(n == 1)// (x*res)%mod// else if((n & BigInt(1)) == BigInt(1))// powi((x*x)%mod,n >> 1,(res*x)%mod)// else// powi((x*x)%mod,n >> 1,res)// }// powi(x,n,1)// }def main() : Unit = {val mod = 129402307val n,m = nextBigIntprintln(n.modPow(m,mod))// println(pow(n,m,mod))// println(pow((n % mod).toLong, m ,mod))}}// ----------------------------------------------------------------------------0// ----------------------------------------------------------------------------0object Main {def main(args: Array[String]) : Unit = {val console = new MyConsole(Console.in, Console.out, Console.err)val solver = new Solver(console)solver.main()console.flush()}}package net.pushl.io {import java.io.{BufferedReader, PrintWriter, PrintStream, PushbackReader}class MyConsole(val in: BufferedReader, val _out: PrintStream,val err: PrintStream) {// PrintWriter do not flush automaticallyval out = new PrintWriter(_out,false)// If argument is null, there are ambiguous which function will be calleddef print(obj: Any) = out.print(if(obj == null) "null" else obj.toString)def println() = out.println()def println(obj: Any) = out.println(obj)def printf(text: String, args: Any*) = out.printf(text.format(args : _*))// NOTE: YOU MUST FLUSH BEFORE END OF MAINdef flush() = out.flush()def debugln(obj: Any) = err.println(obj)def readIntVector() : Vector[Int] = parseLineToVector(() => nextInt)def readLongVector() : Vector[Long] = parseLineToVector(() => nextLong)def readStringVector() : Vector[String] = parseLineToVector(() => nextString)def nextInt() : Int = nextLong().toIntdef nextBigInt() : BigInt = BigInt(nextString())def nextBigDecimal( ) : BigDecimal = BigDecimal(nextString())def nextDouble() : Double = nextString().toDoubledef nextLong() : Long = {if(!goNextValuable())throw new NoSuchElementException("Reading long failed")val sgn = if(peek == '-') -1l else 1if(sgn == -1l) read()if(peek < '0' || '9' < peek)throw new NumberFormatException(s"readLong found only '-' or no number")@tailrecdef readLong(next: Int, cur: Long) : Long =if('0' <= next && next <= '9')readLong(readWithoutCheckingPeeked(), cur*10 + next-'0')else if(isEnd(next) || isSpaceOrControl(next))sgn*curelsethrow new NumberFormatException(s"readLong found strange byte $next")val res = readLong(read(),0)skipTrailingSpaces()res}def nextString() : String = {if(!goNextValuable())throw new NoSuchElementException("Reading String failed")val builder = new StringBuilder@tailrecdef appendCode(next: Int) : String = {if(isEnd(next) || isSpaceOrControl(next)){builder.toString}else{builder.append(next.toChar)appendCode(readWithoutCheckingPeeked())}}val res = appendCode(read())skipTrailingSpaces()res}// TODO: refactoring to marge nextStringdef readLine() : String = {if(isEnd(peek))throw new NoSuchElementException("Reading Line failed")val builder = new StringBuilder@tailrecdef appendCode(next: Int) : String = {if(isEnd(next) || isNewLine(next)){builder.toString}else{builder.append(next.toChar)appendCode(read())}}appendCode(read())}// helpersprivate[this] var peeked: Option[Int] = Noneprivate[this] var last = -1private def read() = {val res = peeked match {case None => in.read()case Some(a) => { peeked = None; a }}last = resres}@inline private def readWithoutCheckingPeeked() = {val res = in.read()last = resres}@inline private def peek() =peeked match {case None => {val res = in.read()peeked = Some(res)res}case Some(a) => a}@inline private def isEnd(c: Int) = c == -1@inline private def isNewLine(c: Int) = c == 10 || c == 13 // LF and CR@inline private def isThereReadable() = !isEnd(peek)// XXX: this limits c is ASCII?@inline private def isSpaceOrControl(c: Int) = (0 <= c && c <= 32) || c == 127@tailrecfinal private def goNextNotSpaceNorControl() : Unit =if(isSpaceOrControl(peek)){read()goNextNotSpaceNorControl()}final private def skipTrailingSpaces() : Unit = {@tailrecdef skipTrailingSpacesAux() : Unit = {if(!isNewLine(last) && !isNewLine(peek) && isSpaceOrControl(peek)){read()skipTrailingSpacesAux()}}skipTrailingSpacesAuxif(!isNewLine(last) && isNewLine(peek)) {val _ = read()}}@tailrecfinal private def skipTrailingSpacesAndNewline() : Unit =if(isNewLine(peek)){val _ = read() // windows causes error. maybe.}else if(isSpaceOrControl(peek)){read()skipTrailingSpacesAndNewline()}@inline private def goNextValuable() = {goNextNotSpaceNorControl()isThereReadable()}@inline private def parseLineToVector[X](parser: () => X) : Vector[X] = {import scala.collection.immutable.VectorBuilderval vb = new VectorBuilder[X]()@tailrecdef parseLineToVectorAux(first: Boolean=false) : Vector[X] =if((!first && isNewLine(last)) || isNewLine(peek) || isEnd(peek)) {vb.result}else{vb += parser()parseLineToVectorAux()}parseLineToVectorAux(true)}}}