結果

問題 No.16 累乗の加算
ユーザー 抹茶アイス抹茶アイス
提出日時 2023-07-25 16:23:04
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 576 ms / 5,000 ms
コード長 1,101 bytes
コンパイル時間 13,699 ms
コンパイル使用メモリ 173,032 KB
実行使用メモリ 182,500 KB
最終ジャッジ日時 2024-04-10 08:22:07
合計ジャッジ時間 18,189 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
30,720 KB
testcase_01 AC 75 ms
30,464 KB
testcase_02 AC 199 ms
30,584 KB
testcase_03 AC 155 ms
30,336 KB
testcase_04 AC 170 ms
30,720 KB
testcase_05 AC 198 ms
30,720 KB
testcase_06 AC 576 ms
30,592 KB
testcase_07 AC 274 ms
30,324 KB
testcase_08 AC 342 ms
30,452 KB
testcase_09 AC 404 ms
30,592 KB
testcase_10 AC 536 ms
30,464 KB
testcase_11 AC 66 ms
30,464 KB
testcase_12 AC 548 ms
30,444 KB
testcase_13 AC 46 ms
182,500 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (102 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

namespace yukicoder
{
    public class Program
    {
        public static void Main()
        {
            var line = Console.ReadLine().Split(' ');
            var x = long.Parse(line[0]);
            var n = int.Parse(line[1]);
            line = Console.ReadLine().Split(' ');
            var a = new long[n];
            long sum = 0;
            for(var i= 0; i < n; i++)
            {
                a[i] = int.Parse(line[i]);
            }
            var q = 1000003;
            var k = new List<long> { 1, x };
            while (k[1] % q > 1)
            {
                k[1] *= x;
                k[1] %= q;
                k[0]++;
            }
            for (var i = 0; i < n; i++)
            {
                a[i] %= k[0];
                long m = 1;
                for(var j = 0; j < a[i]; j++)
                {
                    m *= x;
                    m %= q;
                }
                sum += m;
                sum %= q;
            }
            Console.WriteLine(sum);
        }
    }
}
0