結果

問題 No.16 累乗の加算
ユーザー mbanmban
提出日時 2016-12-22 14:30:02
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 983 bytes
コンパイル時間 4,172 ms
コンパイル使用メモリ 107,008 KB
実行使用メモリ 23,756 KB
最終ジャッジ日時 2023-09-08 12:04:53
合計ジャッジ時間 5,465 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
21,808 KB
testcase_01 AC 60 ms
21,860 KB
testcase_02 AC 60 ms
19,616 KB
testcase_03 AC 61 ms
21,756 KB
testcase_04 AC 62 ms
23,704 KB
testcase_05 AC 63 ms
23,720 KB
testcase_06 AC 62 ms
23,684 KB
testcase_07 AC 62 ms
21,736 KB
testcase_08 AC 63 ms
21,712 KB
testcase_09 AC 59 ms
23,756 KB
testcase_10 AC 58 ms
21,700 KB
testcase_11 AC 58 ms
21,756 KB
testcase_12 AC 59 ms
21,724 KB
testcase_13 AC 59 ms
21,700 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

class Magatro
{
    const int MOD = 1000003;
    static void Main()
    {
        int x, N;
        string[] s = Console.ReadLine().Split(' ');
        x = int.Parse(s[0]);
        N = int.Parse(s[1]);
        int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        long cnt = 0;
        for(int i = 0; i < N; i++)
        {
            cnt = (cnt + MyPow(x, a[i])) % MOD;
        }
        Console.WriteLine(cnt);

    }
static long MyPow(long a,long b)
    {
        long res = 1;
        while (b > 0)
        {
            if (b % 2 == 0)
            {
                a = (a * a) % MOD;
                b /= 2;
            }
            else
            {
                res = (res * a) % MOD;
                b--;
            }
        }
        return res;
    }
}
0