結果
問題 | No.129 お年玉(2) |
ユーザー | 14番 |
提出日時 | 2016-04-17 18:31:33 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 82 ms / 5,000 ms |
コード長 | 4,212 bytes |
コンパイル時間 | 3,381 ms |
コンパイル使用メモリ | 108,672 KB |
実行使用メモリ | 22,272 KB |
最終ジャッジ日時 | 2024-05-05 23:02:26 |
合計ジャッジ時間 | 4,446 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 27 ms
18,432 KB |
testcase_01 | AC | 82 ms
21,956 KB |
testcase_02 | AC | 21 ms
17,664 KB |
testcase_03 | AC | 24 ms
18,048 KB |
testcase_04 | AC | 25 ms
18,048 KB |
testcase_05 | AC | 50 ms
22,004 KB |
testcase_06 | AC | 44 ms
20,852 KB |
testcase_07 | AC | 58 ms
22,272 KB |
testcase_08 | AC | 58 ms
22,016 KB |
testcase_09 | AC | 45 ms
20,224 KB |
testcase_10 | AC | 68 ms
22,016 KB |
testcase_11 | AC | 47 ms
21,376 KB |
testcase_12 | AC | 28 ms
18,176 KB |
testcase_13 | AC | 27 ms
18,176 KB |
testcase_14 | AC | 42 ms
20,320 KB |
testcase_15 | AC | 40 ms
20,224 KB |
testcase_16 | AC | 47 ms
21,068 KB |
testcase_17 | AC | 37 ms
20,224 KB |
testcase_18 | AC | 56 ms
22,144 KB |
testcase_19 | AC | 69 ms
22,000 KB |
testcase_20 | AC | 51 ms
22,016 KB |
testcase_21 | AC | 41 ms
20,224 KB |
testcase_22 | AC | 48 ms
21,760 KB |
testcase_23 | AC | 61 ms
22,272 KB |
testcase_24 | AC | 74 ms
22,060 KB |
testcase_25 | AC | 43 ms
20,992 KB |
testcase_26 | AC | 53 ms
22,016 KB |
testcase_27 | AC | 52 ms
22,008 KB |
testcase_28 | AC | 53 ms
21,120 KB |
testcase_29 | AC | 21 ms
17,792 KB |
testcase_30 | AC | 21 ms
17,664 KB |
testcase_31 | AC | 22 ms
17,664 KB |
testcase_32 | AC | 25 ms
17,664 KB |
testcase_33 | AC | 20 ms
17,536 KB |
testcase_34 | AC | 25 ms
17,792 KB |
testcase_35 | AC | 24 ms
17,792 KB |
testcase_36 | AC | 27 ms
18,048 KB |
testcase_37 | AC | 27 ms
17,920 KB |
testcase_38 | AC | 30 ms
19,072 KB |
testcase_39 | AC | 31 ms
18,816 KB |
testcase_40 | AC | 35 ms
19,328 KB |
testcase_41 | AC | 41 ms
20,480 KB |
testcase_42 | AC | 33 ms
19,968 KB |
testcase_43 | AC | 30 ms
18,304 KB |
testcase_44 | AC | 76 ms
22,068 KB |
testcase_45 | AC | 31 ms
19,072 KB |
testcase_46 | AC | 26 ms
18,560 KB |
testcase_47 | AC | 70 ms
21,996 KB |
testcase_48 | AC | 63 ms
22,016 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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(); } }