結果
問題 |
No.16 累乗の加算
|
ユーザー |
![]() |
提出日時 | 2017-02-17 09:37:40 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 55 ms / 5,000 ms |
コード長 | 1,068 bytes |
コンパイル時間 | 2,606 ms |
コンパイル使用メモリ | 76,892 KB |
実行使用メモリ | 36,976 KB |
最終ジャッジ日時 | 2024-06-26 05:20:10 |
合計ジャッジ時間 | 3,639 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
ソースコード
import java.util.*; import java.io.*; public class Main { static int mod=1000003; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int x=Integer.parseInt(st.nextToken()); int n=Integer.parseInt(st.nextToken()); int[] a=new int[n]; st=new StringTokenizer(br.readLine()); for(int i=0;i<n;i++){ a[i]=Integer.parseInt(st.nextToken()); } long sum=0; for(int i=0;i<n;i++){ //System.out.println(x+"^"+a[i]+"="+pow(x,a[i])); sum=(sum+pow(x,a[i]))%mod; //System.out.println(sum); }System.out.println(sum%mod); } static long pow(long x,int n){ //System.out.println(x+" "+n); x%=mod; if(n==1){ return x; } if(n==0){ return 1; } if(n%2==0){ return pow(x*x,n/2)%mod; }else{ return (pow(x,n-1)*x)%mod; } } }