結果
問題 | No.16 累乗の加算 |
ユーザー |
![]() |
提出日時 | 2017-10-06 16:14:16 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 804 bytes |
コンパイル時間 | 3,790 ms |
コンパイル使用メモリ | 85,008 KB |
実行使用メモリ | 43,100 KB |
最終ジャッジ日時 | 2024-11-17 00:31:31 |
合計ジャッジ時間 | 7,433 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 14 |
ソースコード
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);}System.out.println("x="+x+"dif="+dif+"mem="+mem);ans=(ans+mem)%beki;cnt+=(a[i]-cnt);System.out.println(ans);}System.out.println(ans);}}