結果

問題 No.915 Plus Or Multiple Operation
ユーザー tomomo2b2tomomo2b2
提出日時 2019-10-25 21:50:41
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,216 bytes
コンパイル時間 2,434 ms
コンパイル使用メモリ 105,600 KB
実行使用メモリ 28,544 KB
最終ジャッジ日時 2024-04-24 18:36:40
合計ジャッジ時間 8,811 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

class MyClass
{
    public static void Solve()
    {
        var Q = int.Parse(Console.ReadLine());
        for (int _i = 0; _i < Q; _i++)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var A = input[0];
            var B = input[1];
            var C = input[2];
            var queue = new Queue<int[]>();
            queue.Enqueue(new[] { A, 0 });
            var ans = 0;
            while (A > 0)
            {
                if (A % C == 0)
                {
                    A /= C;
                    ans++;
                }
                else
                {
                    A -= A % C;
                    ans++;
                }
            }
            if (A != 0)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine((long)B * ans);
            }
        }
    }

    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}
0