結果
問題 | No.16 累乗の加算 |
ユーザー | mudbdb |
提出日時 | 2015-07-12 09:17:14 |
言語 | C90 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 1,099 bytes |
コンパイル時間 | 677 ms |
コンパイル使用メモリ | 25,572 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-09-08 11:41:24 |
合計ジャッジ時間 | 1,348 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 0 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 0 ms
4,376 KB |
testcase_04 | AC | 0 ms
4,380 KB |
testcase_05 | AC | 0 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 1 ms
4,380 KB |
testcase_11 | AC | 1 ms
4,376 KB |
testcase_12 | AC | 0 ms
4,380 KB |
testcase_13 | AC | 1 ms
4,380 KB |
ソースコード
#include <stdio.h> #include <stdlib.h> int main() { int X; int N; int *A; scanf("%d", &X); scanf("%d", &N); A = (int*)malloc(sizeof(int)*N); int i; for (i=0; i<N; i++) scanf("%d", &(A[i])); int mod = 1000003; // 2^26 = 67108864 // A[i] <= 100000000 // 2^27 = 134217728 // // A[i] = 2^26 *bit[26] +...+ 2^0 *bit[0] // X^A[i] = X^(2^26 *bit[26])*...* X^(2^0 *bit[0]) // = (X^(2^26))^bit[26] *...*(X^(2^0))^bit[0] int table_n = 27; long long int *table = (long long*)malloc(sizeof(long long int)*table_n); table[0] = (X % mod); for (i=1; i<table_n; i++) { table[i] = ((table[i-1]*table[i-1]) % mod); } int j; long long int total; long long int item; if (X == 1) { total = N; total %= mod; } else { total = 0; for (i=0; i<N; i++) { item = 1; if (A[i] != 0) { for (j=0; j<table_n; j++) { if (A[i] & (1 << j)) { item *= table[j]; item %= mod; } } } total += item; total %= mod; } } printf("%d\n", total); return 0; }