結果
| 問題 |
No.16 累乗の加算
|
| コンテスト | |
| ユーザー |
yusaka
|
| 提出日時 | 2015-06-24 21:53:12 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,004 bytes |
| コンパイル時間 | 114 ms |
| コンパイル使用メモリ | 23,680 KB |
| 実行使用メモリ | 8,352 KB |
| 最終ジャッジ日時 | 2024-07-07 17:30:25 |
| 合計ジャッジ時間 | 6,574 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 TLE * 1 -- * 11 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:40:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
40 | scanf("%d %d\n", &x, &n);
| ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:41:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
41 | scanf("%[^\n]", input);
| ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#define N 100
#define MAX 1000
int get_start_value(char input[], int *offset, int n) {
if (input[*offset] == '\0' || input[*offset] == ' ') {
return n;
}
n = 10 * n + (input[*offset] - '0');
*offset = *offset + 1;
return get_start_value(input, offset, n);
}
void parse_input(int num[], char input[], int offset, int i) {
if (input[offset] == '\0') {
return;
}
num[i] = get_start_value(input, &offset, 0);
i++;
parse_input(num, input, offset + 1, i);
}
int execute_expt_mod(int x, int n) {
int res = 1;
int i = 0;
for (;i<n;i++) {
res *= x;
if (res > 1000003) {
res %= 1000003;
}
}
return res;
}
int main (void) {
int x;
int n;
char input[MAX];
int input_as_int[N];
scanf("%d %d\n", &x, &n);
scanf("%[^\n]", input);
parse_input(input_as_int, input, 0, 0);
int sum = 0;
int i;
for (i = 0; i < n; i++){
sum += execute_expt_mod(x, input_as_int[i]);
}
sum %= 1000003;
printf("%d", sum);
return 0;
}
yusaka