結果
| 問題 |
No.25 有限小数
|
| コンテスト | |
| ユーザー |
明智重蔵
|
| 提出日時 | 2015-10-31 18:31:32 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,702 bytes |
| コンパイル時間 | 1,539 ms |
| コンパイル使用メモリ | 114,964 KB |
| 実行使用メモリ | 39,620 KB |
| 最終ジャッジ日時 | 2024-09-13 06:25:21 |
| 合計ジャッジ時間 | 8,244 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 TLE * 1 -- * 13 |
コンパイルメッセージ
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.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("7");
WillReturn.Add("5");
//4
//7/5=1.4で有限小数で表すことができるので、最後の数は4となる
}
else if (InputPattern == "Input2") {
WillReturn.Add("2");
WillReturn.Add("3");
//-1
//2/3は有限小数で表すことが出来ないので-1となる
}
else if (InputPattern == "Input3") {
WillReturn.Add("10");
WillReturn.Add("3");
//-1
}
else if (InputPattern == "Input4") {
WillReturn.Add("20");
WillReturn.Add("2");
//1
//20/2は10になるが、0でない小さい位からみて最後の数なので1を出力する
}
else if (InputPattern == "Input5") {
WillReturn.Add("12345");
WillReturn.Add("30517578125");
//6
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
private struct OnePairDef
{
internal long Syou;
internal long Amari;
}
static void Main()
{
List<string> InputList = GetInputList();
long N = long.Parse(InputList[0]);
long M = long.Parse(InputList[1]);
long Syou, Amari;
//整数除算で割り切れる場合
if (N % M == 0) {
Syou = N / M;
while (true) {
if (Syou % 10 > 0) {
Console.WriteLine(Syou % 10);
return;
}
Syou /= 10;
}
}
//整数除算で割り切れない場合
long Wararerukazu = N;
var OnePairList = new List<OnePairDef>();
do {
Syou = Wararerukazu / M;
Amari = Wararerukazu % M;
OnePairDef WillAdd;
WillAdd.Syou = Syou;
WillAdd.Amari = Amari;
int wkInd = OnePairList.FindIndex(X => X.Syou == WillAdd.Syou
&& X.Amari == WillAdd.Amari);
if (wkInd >= 0) {
Console.WriteLine(-1);
return;
}
OnePairList.Add(WillAdd);
Wararerukazu = Amari * 10;
} while (Amari != 0);
Console.WriteLine(Syou);
}
}
明智重蔵