結果

問題 No.129 お年玉(2)
ユーザー 14番14番
提出日時 2016-04-17 18:31:33
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 126 ms / 5,000 ms
コード長 4,212 bytes
コンパイル時間 2,571 ms
コンパイル使用メモリ 108,996 KB
実行使用メモリ 27,020 KB
最終ジャッジ日時 2023-08-18 17:38:18
合計ジャッジ時間 7,965 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
22,844 KB
testcase_01 AC 126 ms
26,984 KB
testcase_02 AC 56 ms
18,936 KB
testcase_03 AC 61 ms
20,800 KB
testcase_04 AC 60 ms
20,816 KB
testcase_05 AC 89 ms
24,904 KB
testcase_06 AC 82 ms
24,884 KB
testcase_07 AC 97 ms
24,948 KB
testcase_08 AC 99 ms
25,028 KB
testcase_09 AC 79 ms
24,972 KB
testcase_10 AC 101 ms
24,844 KB
testcase_11 AC 84 ms
22,792 KB
testcase_12 AC 65 ms
20,728 KB
testcase_13 AC 63 ms
20,828 KB
testcase_14 AC 81 ms
22,844 KB
testcase_15 AC 81 ms
22,920 KB
testcase_16 AC 87 ms
24,832 KB
testcase_17 AC 76 ms
20,740 KB
testcase_18 AC 100 ms
24,856 KB
testcase_19 AC 110 ms
27,008 KB
testcase_20 AC 91 ms
24,824 KB
testcase_21 AC 79 ms
22,908 KB
testcase_22 AC 87 ms
22,968 KB
testcase_23 AC 102 ms
25,000 KB
testcase_24 AC 115 ms
26,956 KB
testcase_25 AC 83 ms
24,876 KB
testcase_26 AC 94 ms
24,888 KB
testcase_27 AC 92 ms
27,012 KB
testcase_28 AC 91 ms
24,840 KB
testcase_29 AC 57 ms
20,828 KB
testcase_30 AC 58 ms
20,804 KB
testcase_31 AC 59 ms
20,860 KB
testcase_32 AC 61 ms
18,748 KB
testcase_33 AC 57 ms
20,748 KB
testcase_34 AC 62 ms
20,980 KB
testcase_35 AC 62 ms
22,896 KB
testcase_36 AC 62 ms
20,884 KB
testcase_37 AC 63 ms
22,744 KB
testcase_38 AC 67 ms
20,820 KB
testcase_39 AC 67 ms
20,876 KB
testcase_40 AC 73 ms
20,980 KB
testcase_41 AC 78 ms
24,912 KB
testcase_42 AC 70 ms
18,764 KB
testcase_43 AC 64 ms
20,780 KB
testcase_44 AC 118 ms
27,020 KB
testcase_45 AC 68 ms
22,712 KB
testcase_46 AC 64 ms
20,824 KB
testcase_47 AC 110 ms
26,924 KB
testcase_48 AC 100 ms
25,008 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.Generic;
using System.Text;
using System.Linq;
 
class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        long yosan = long.Parse(Reader.ReadLine()) / 1000;
        int ninzu = int.Parse(Reader.ReadLine());
        long hitori = yosan / ninzu;
        long amari = yosan % ninzu;
        
        this.CreatePrimeNumberList(ninzu);
        
        long ans = 1;
        if(amari > 0) {
            Dictionary<long, long> total = new Dictionary<long, long>();
            for(int i=0; i<amari; i++) {
                Dictionary<long, long> tmpDic = this.GetSoinsu(ninzu-i);
                List<long> keyList = new List<long>(tmpDic.Keys);
                keyList.ForEach((a)=>{
                if(total.ContainsKey(a)) {
                    total[a]+=tmpDic[a];
                } else
                {
                    total.Add(a, tmpDic[a]);
                }
                });
            }
            Dictionary<long, long> ordTotal = new Dictionary<long, long>();
            for(long i=2; i<=amari; i++) {
               Dictionary<long, long> tmp = this.GetSoinsu(i);
               foreach (long key in tmp.Keys)
               {
                   if(ordTotal.ContainsKey(key)) {
                       ordTotal[key]+=tmp[key];
                   } else
                   {
                       ordTotal.Add(key, tmp[key]);
                   }
               }
            }
            List<long> keyList2 = new List<long>(ordTotal.Keys);
            keyList2.ForEach((a)=>{
                total[a] -= ordTotal[a]; 
            });
            
            foreach (long key in total.Keys)
            {
                for(int i=0; i<total[key]; i++) {
                    ans *= key;
                    ans = ans % 1000000000;
                }
            }
        }
        Console.WriteLine(ans);
     }
     private Dictionary<long, long> GetSoinsu(long num) {
         Dictionary<long, long> dic = new Dictionary<long, long>();
         long current = num;
         foreach (int prime in this.PrimeNumberList)
         {
             while (current % prime == 0)
             {
                 if(!dic.ContainsKey(prime)) {
                     dic.Add(prime, 0);
                 }
                 dic[prime]++;
                 current = current / prime;
                 if(current == 1) {
                     break;
                 }
             }
             if(current == 1) {
                 break;
             }
         }
         return dic;
     }
     
     private List<int> PrimeNumberList = new List<int>();
     private void CreatePrimeNumberList(int num) {
         bool[] flag = new bool[num+1];
         List<int> primeNumbers = new List<int>();
         for(int i=2; i<=num; i++) {
             if(!flag[i]) {
                 primeNumbers.Add(i);
                 for(int j=1; j<=num/i; j++) {
                     flag[i*j] = true;
                 }
             }
         }
         this.PrimeNumberList = primeNumbers;
     }
    

    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


24500
9


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