結果

問題 No.16 累乗の加算
ユーザー しらゆきしらゆき
提出日時 2016-01-12 00:34:42
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 2,378 bytes
コンパイル時間 4,557 ms
コンパイル使用メモリ 103,888 KB
実行使用メモリ 24,024 KB
最終ジャッジ日時 2023-09-08 11:51:51
合計ジャッジ時間 4,977 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
24,024 KB
testcase_01 AC 60 ms
23,920 KB
testcase_02 AC 61 ms
21,872 KB
testcase_03 AC 60 ms
21,828 KB
testcase_04 AC 60 ms
23,984 KB
testcase_05 AC 60 ms
21,764 KB
testcase_06 AC 60 ms
21,984 KB
testcase_07 AC 62 ms
19,896 KB
testcase_08 AC 61 ms
21,740 KB
testcase_09 AC 59 ms
21,824 KB
testcase_10 AC 59 ms
21,944 KB
testcase_11 AC 59 ms
21,908 KB
testcase_12 AC 59 ms
21,816 KB
testcase_13 AC 59 ms
21,840 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.Linq;
using System.Collections.Generic;

class Program
{

    static void Main()
    {
        long x, n;
        mul(out x, out n);
        var a = rla();

        long ans = 0;

        for(int i=0;i< n; i++)
            ans = (ans + pow(x, a[i])) % 1000003;

        Console.WriteLine(ans);
    }

    static long pow(long x,long n)
    {
        long y = 1, p = x;
        while (n > 0)
        {
            if (n % 2 == 0)
            {
                p = (p * p) % 1000003;
                n /= 2;
            }
            else
            {
                y = (y * p) % 1000003;
                n--;
            }
        }
        return y;
    }

    #region Scan
    static int ri() { return int.Parse(Console.ReadLine().Trim()); }
    static long rl() { return long.Parse(Console.ReadLine().Trim()); }
    static double rd() { return double.Parse(Console.ReadLine().Trim()); }
    static string rs() { return Console.ReadLine().Trim(); }
    static int[] ria() { return Console.ReadLine().Trim().Split().Select(int.Parse).ToArray(); }
    static long[] rla() { return Console.ReadLine().Trim().Split().Select(long.Parse).ToArray(); }
    static double[] rda() { return Console.ReadLine().Trim().Split().Select(double.Parse).ToArray(); }
    static string[] rsa() { return Console.ReadLine().Trim().Split(); }
    static void mul(out int a, out int b) { var arr = ria(); a = arr[0]; b = arr[1]; }
    static void mul(out int a, out int b, out int c) { var arr = ria(); a = arr[0]; b = arr[1]; c = arr[2]; }
    static void mul(out int a, out int b, out int c, out int d) { var arr = ria(); a = arr[0]; b = arr[1]; c = arr[2]; d = arr[3]; }
    static void mul(out long a, out long b) { var arr = rla(); a = arr[0]; b = arr[1]; }
    static void mul(out long a, out long b, out long c) { var arr = rla(); a = arr[0]; b = arr[1]; c = arr[2]; }
    static void mul(out long a, out long b, out long c, out long d) { var arr = rla(); a = arr[0]; b = arr[1]; c = arr[2]; d = arr[3]; }
    #endregion
    #region Math
    const int mod = 1000000007;
    static bool isprime(long n){ if (n < 2) return false; for (long i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; }
    static long gcd(long a, long b) { return a == 0 ? b : gcd(b % a, a); }
    static long lcm(long a, long b) { return a * b / gcd(a, b); }
    #endregion
}
0