結果
問題 |
No.487 2017 Calculation(2017の計算)
|
ユーザー |
![]() |
提出日時 | 2022-08-02 09:47:01 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 1,241 bytes |
コンパイル時間 | 2,307 ms |
コンパイル使用メモリ | 77,560 KB |
実行使用メモリ | 50,664 KB |
最終ジャッジ日時 | 2024-07-23 02:39:32 |
合計ジャッジ時間 | 3,875 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int m = sc.nextInt(); long ans = 2017 + pow(2017 * 2017 % m, 2017, m); ans %= m; System.out.println(ans); } static long pow(long x, int p, int m) { if (p == 0) { return 1; } else if (p % 2 == 0) { return pow(x * x % m, p / 2, m); } else { return pow(x, p - 1, m) * x % m; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }