結果

問題 No.16 累乗の加算
ユーザー 14番14番
提出日時 2016-03-31 15:28:58
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 66 ms / 5,000 ms
コード長 2,070 bytes
コンパイル時間 2,302 ms
コンパイル使用メモリ 102,516 KB
実行使用メモリ 26,196 KB
最終ジャッジ日時 2023-09-08 11:57:07
合計ジャッジ時間 4,124 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
21,364 KB
testcase_01 AC 58 ms
21,352 KB
testcase_02 AC 66 ms
24,696 KB
testcase_03 AC 60 ms
23,680 KB
testcase_04 AC 60 ms
21,732 KB
testcase_05 AC 62 ms
24,356 KB
testcase_06 AC 62 ms
21,128 KB
testcase_07 AC 62 ms
22,760 KB
testcase_08 AC 64 ms
23,816 KB
testcase_09 AC 64 ms
26,196 KB
testcase_10 AC 63 ms
23,140 KB
testcase_11 AC 59 ms
21,360 KB
testcase_12 AC 63 ms
25,148 KB
testcase_13 AC 61 ms
22,072 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.Text;

public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        
        int[] inpt = Reader.GetInt();
        int baseNum = inpt[0];
        int itemCount = inpt[1];
        
        int[] powList = Reader.GetInt();
        
        long ans = 0;
        
        foreach (int pow in powList)
        {
            ans += this.GetSubTotal(baseNum, pow);
            ans = ans % Div;
        }
        
        
        Console.WriteLine(ans);

    }
    
    private long GetSubTotal(int baseNum, int pow) {
        if(dic[pow] > 0) {
            return dic[pow];
        }
        long ans = 1;
        if(pow <= 4) {
            ans = (long)Math.Pow(baseNum, pow) % Div;
        } else {
            int half = pow / 2;
            ans = this.GetSubTotal(baseNum, half);
            ans = ans * this.GetSubTotal(baseNum, pow - half) % Div;
        }
        dic[pow] = ans;
        return ans;
    }
    
    private long[] dic = new long[100000000 + 1];
    
    private int Div = 1000003;
    
    
    public class Reader {
        private static String InitText = @"



        ";
        
        private static System.IO.StringReader sr = null;
        
        public static bool IsDebug = true;
        
        public static string ReadLine() {
            if(IsDebug) {
                if(sr == null) {
                    sr = new System.IO.StringReader(InitText.Trim());
                }
                return sr.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
        public static int[] GetInt(char delimiter = ' ') {
            string[] inpt = ReadLine().Split(delimiter);
            int[] ret = new int[inpt.Length];
            for(int i=0; i<inpt.Length; i++) {
                ret[i] = int.Parse(inpt[i]);
            }
            return ret;
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0