結果
| 問題 | No.16 累乗の加算 |
| コンテスト | |
| ユーザー |
mudbdb
|
| 提出日時 | 2015-07-12 09:17:14 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 1,099 bytes |
| コンパイル時間 | 347 ms |
| コンパイル使用メモリ | 22,400 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-26 04:57:23 |
| 合計ジャッジ時間 | 932 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:54:12: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
54 | printf("%d\n", total);
| ~^ ~~~~~
| | |
| int long long int
| %lld
main.c:8:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | scanf("%d", &X);
| ^~~~~~~~~~~~~~~
main.c:9:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | scanf("%d", &N);
| ^~~~~~~~~~~~~~~
main.c:12:23: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | for (i=0; i<N; i++) scanf("%d", &(A[i]));
| ^~~~~~~~~~~~~~~~~~~~
ソースコード
#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;
}
mudbdb