結果

問題 No.1464 Number Conversion
ユーザー bluemeganebluemegane
提出日時 2021-04-17 11:33:41
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 951 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 61,544 KB
実行使用メモリ 25,392 KB
最終ジャッジ日時 2023-09-16 18:49:19
合計ジャッジ時間 4,961 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
20,712 KB
testcase_01 AC 64 ms
23,400 KB
testcase_02 AC 57 ms
21,492 KB
testcase_03 AC 48 ms
20,804 KB
testcase_04 AC 60 ms
21,064 KB
testcase_05 AC 58 ms
20,984 KB
testcase_06 AC 59 ms
21,012 KB
testcase_07 AC 58 ms
21,292 KB
testcase_08 AC 59 ms
21,232 KB
testcase_09 AC 59 ms
21,288 KB
testcase_10 AC 58 ms
21,128 KB
testcase_11 AC 59 ms
21,304 KB
testcase_12 AC 60 ms
21,416 KB
testcase_13 AC 57 ms
21,288 KB
testcase_14 AC 58 ms
21,376 KB
testcase_15 AC 60 ms
19,364 KB
testcase_16 AC 61 ms
23,420 KB
testcase_17 AC 61 ms
19,240 KB
testcase_18 AC 62 ms
23,436 KB
testcase_19 AC 59 ms
23,348 KB
testcase_20 AC 61 ms
25,392 KB
testcase_21 AC 59 ms
21,228 KB
testcase_22 AC 58 ms
19,480 KB
testcase_23 AC 50 ms
20,776 KB
testcase_24 AC 59 ms
21,500 KB
testcase_25 AC 59 ms
23,400 KB
testcase_26 AC 59 ms
19,404 KB
testcase_27 AC 58 ms
21,092 KB
testcase_28 AC 51 ms
20,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var s = Console.ReadLine().Trim();
        var p = s.IndexOf('.');
        if (p == -1) Console.WriteLine(s + "/1");
        else getAns(s, p);
    }
    static void getAns(string s, int p)
    {
        var s2 = s.Replace(".", "");
        var t1 = long.Parse(s2);
        var t2 = (long)Pow(10, s.Length - (p + 1));
        if (t1 % t2 == 0) { Console.WriteLine("{0}/1", t1 / t2); return; }
        if (t2 % t1 == 0) { Console.WriteLine("1/{0}", t2 / t1); return; }
        var imax = (int)Sqrt(Min(t1, t2)) + 1;
        for (int i = 2; i <= imax; i++)
        {
            while (true)
            {
                if (t1 % i == 0 && t2 % i == 0)
                {
                    t1 /= i;
                    t2 /= i;
                }
                else break;
            }
        }
        Console.WriteLine("{0}/{1}", t1, t2);
    }
}
0