結果

問題 No.1275 綺麗な式
コンテスト
ユーザー qand
提出日時 2020-09-21 15:28:11
言語 Java
(openjdk 26.0.2.1 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 710 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,504 ms
コンパイル使用メモリ 85,572 KB
実行使用メモリ 51,424 KB
最終ジャッジ日時 2026-08-21 09:37:22
合計ジャッジ時間 8,209 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12 RE * 48
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		long a = Long.parseLong(sc.next());
		int b = Integer.parseInt(sc.next());
		int n = Integer.parseInt(sc.next());
		sc.close();
		if(n == 0) ou.println(2);
		else{
			long[] q = new long[n + 1];
			q[0] = 2;
			q[1] = 2 * a;
			for(int i = 2 ; i <= n ; i++){
				long tmp = a * (long)a;
				tmp %= (int)Math.pow(10 , 9) + 7;
				q[i] = ((2 * a * (long)q[i - 1] - (tmp - b) * q[i - 2]) % (int)(Math.pow(10 , 9) + 7));
			}
			while(q[n] < 0) q[n] += (long)Math.pow(10 , 9) + 7;
			ou.println(q[n]);
		}
		ou.flush();
	}
}
0