結果
問題 | No.129 お年玉(2) |
ユーザー |
![]() |
提出日時 | 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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
コンパイルメッセージ
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 = @"245009";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();}}