結果

問題 No.1350 2019-6problem
ユーザー bluemeganebluemegane
提出日時 2021-05-18 20:40:02
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,143 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 104,448 KB
実行使用メモリ 18,048 KB
最終ジャッジ日時 2024-04-17 08:07:38
合計ジャッジ時間 2,201 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
17,664 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 24 ms
17,664 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = long.Parse(line[0]);
        var b = long.Parse(line[1]);
        var k = long.Parse(line[2]);
        getAns(a, b, k);
    }
    static void getAns(long a, long b, long k)
    {
        if (k == 1) { Console.WriteLine(Min(a, b)); return; }
        if (k == 2) { Console.WriteLine(Max(a, b)); return; }
        var ok = long.MaxValue;
        var ng = 1L;
        while (ok - ng > 1)
        {
            var mid = ng + (ok - ng) / 2L;
            var chk = mid / a + mid / b - mid / lcm(a, b);
            if (chk == k) { Console.WriteLine(mid); return; }
            else if (chk > k) ok = mid;
            else ng = mid;
        }
        Console.WriteLine(ok);
    }
    public static long lcm(long a, long b)
    {
        return a * b / gcd(a, b);
    }
    static long gcd(long a, long b)
    {
        if (a < b) return gcd(b, a);
        while (b != 0)
        {
            var w = a % b;
            a = b;
            b = w;
        }
        return a;
    }
}
0