結果
問題 | No.16 累乗の加算 |
ユーザー |
![]() |
提出日時 | 2017-10-06 16:15:11 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 724 bytes |
コンパイル時間 | 3,678 ms |
コンパイル使用メモリ | 77,680 KB |
実行使用メモリ | 54,492 KB |
最終ジャッジ日時 | 2024-11-17 00:31:38 |
合計ジャッジ時間 | 7,189 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 WA * 12 |
ソースコード
import java.util.Arrays;import java.util.Scanner;public class N016 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);long x=sc.nextLong(),n=sc.nextLong();long[] a=new long[(int)n];for(long i=0;i<n;i++){a[(int)i]=sc.nextLong();}Arrays.sort(a);long mem=1;long cnt=0;long ans=0;long beki=(int)Math.pow(10, 6)+3;long buf=(int)Math.pow(2, 20)%beki;for(int i=0;i<n;i++){long dif=a[i]-cnt;if(dif>=20){while(dif>=20){dif-=20;mem=(mem*buf)%beki;}mem=(mem*((int)Math.pow(2, dif)%beki))%beki;}else{mem*=((int)Math.pow(x, dif)%beki);}ans=(ans+mem)%beki;cnt+=(a[i]-cnt);}System.out.println(ans);}}