結果
問題 | No.16 累乗の加算 |
ユーザー |
![]() |
提出日時 | 2016-11-07 16:23:14 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 139 ms / 5,000 ms |
コード長 | 1,429 bytes |
コンパイル時間 | 2,194 ms |
コンパイル使用メモリ | 76,996 KB |
実行使用メモリ | 41,608 KB |
最終ジャッジ日時 | 2024-06-26 05:17:51 |
合計ジャッジ時間 | 4,638 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
ソースコード
import java.util.*;public class Main {private static Scanner sc = new Scanner(System.in);private static long[] ary;private static final long MOD = 1000003;public static void main(String[] args) throws Exception {long x = nextLong();int n = nextInt();ary = nextLong(n);long ans = 0;for (int i = 0;i < n;i++) {ans = (ans+pow(x, ary[i]))%MOD;}System.out.println(ans);}private static long pow(long n, long p) {long ret = 1;while (p > 0) {if ((p&1)==1) ret = ret*n%MOD;n = n*n%MOD;p >>= 1;}return ret;}private static int nextInt() { return sc.nextInt(); }private static long nextLong() { return sc.nextLong(); }private static float nextFloat() { return sc.nextFloat(); }private static int[] nextInt(int n) {int[] ret = new int[n];for (int i = 0;i < n;i++) {ret[i] = nextInt();}return ret;}private static long[] nextLong(int n) {long[] ret = new long[n];for (int i = 0;i < n;i++) {ret[i] = nextLong();}return ret;}private static float[] nextFloat(int n) {float[] ret = new float[n];for (int i = 0;i < n;i++) {ret[i] = nextFloat();}return ret;}}