結果
問題 | No.129 お年玉(2) |
ユーザー | 14番 |
提出日時 | 2016-04-17 18:31:33 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 97 ms / 5,000 ms |
コード長 | 4,212 bytes |
コンパイル時間 | 3,457 ms |
コンパイル使用メモリ | 108,544 KB |
実行使用メモリ | 22,084 KB |
最終ジャッジ日時 | 2024-11-28 00:26:53 |
合計ジャッジ時間 | 6,655 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
18,176 KB |
testcase_01 | AC | 97 ms
22,084 KB |
testcase_02 | AC | 24 ms
17,792 KB |
testcase_03 | AC | 28 ms
17,920 KB |
testcase_04 | AC | 28 ms
17,792 KB |
testcase_05 | AC | 60 ms
21,888 KB |
testcase_06 | AC | 51 ms
20,596 KB |
testcase_07 | AC | 67 ms
22,016 KB |
testcase_08 | AC | 69 ms
22,016 KB |
testcase_09 | AC | 47 ms
20,480 KB |
testcase_10 | AC | 72 ms
22,016 KB |
testcase_11 | AC | 54 ms
21,120 KB |
testcase_12 | AC | 32 ms
18,048 KB |
testcase_13 | AC | 31 ms
17,920 KB |
testcase_14 | AC | 51 ms
20,440 KB |
testcase_15 | AC | 48 ms
20,608 KB |
testcase_16 | AC | 55 ms
21,320 KB |
testcase_17 | AC | 45 ms
19,968 KB |
testcase_18 | AC | 67 ms
21,888 KB |
testcase_19 | AC | 79 ms
21,872 KB |
testcase_20 | AC | 61 ms
21,504 KB |
testcase_21 | AC | 47 ms
20,088 KB |
testcase_22 | AC | 57 ms
21,504 KB |
testcase_23 | AC | 71 ms
21,888 KB |
testcase_24 | AC | 85 ms
21,932 KB |
testcase_25 | AC | 52 ms
20,736 KB |
testcase_26 | AC | 62 ms
21,888 KB |
testcase_27 | AC | 62 ms
21,888 KB |
testcase_28 | AC | 60 ms
21,632 KB |
testcase_29 | AC | 24 ms
17,536 KB |
testcase_30 | AC | 25 ms
17,536 KB |
testcase_31 | AC | 24 ms
17,536 KB |
testcase_32 | AC | 29 ms
18,048 KB |
testcase_33 | AC | 24 ms
17,408 KB |
testcase_34 | AC | 29 ms
17,792 KB |
testcase_35 | AC | 29 ms
17,792 KB |
testcase_36 | AC | 30 ms
17,920 KB |
testcase_37 | AC | 30 ms
17,792 KB |
testcase_38 | AC | 35 ms
18,944 KB |
testcase_39 | AC | 34 ms
18,688 KB |
testcase_40 | AC | 41 ms
19,200 KB |
testcase_41 | AC | 47 ms
20,480 KB |
testcase_42 | AC | 39 ms
19,840 KB |
testcase_43 | AC | 31 ms
18,176 KB |
testcase_44 | AC | 88 ms
21,936 KB |
testcase_45 | AC | 37 ms
19,200 KB |
testcase_46 | AC | 33 ms
18,176 KB |
testcase_47 | AC | 81 ms
21,876 KB |
testcase_48 | AC | 70 ms
21,888 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(); } }