結果
問題 | No.16 累乗の加算 |
ユーザー | yusaka |
提出日時 | 2015-06-24 21:53:12 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,004 bytes |
コンパイル時間 | 457 ms |
コンパイル使用メモリ | 26,668 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-22 00:34:59 |
合計ジャッジ時間 | 7,107 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,384 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | TLE | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
ソースコード
#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; }