結果

問題 No.782 マイナス進数
ユーザー bluemegane
提出日時 2021-05-08 11:02:45
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 688 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 113,424 KB
実行使用メモリ 22,272 KB
最終ジャッジ日時 2024-09-16 09:01:29
合計ジャッジ時間 6,074 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Collections.Generic;
using System;

public class hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var t = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        while (t-- > 0)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            var ans = new List<int>();
            while (true)
            {
                var mod = n % b;
                n /= b;
                if (mod < 0) { n++; mod += (-b); }
                ans.Add(mod);
                if (n == 0) break;
            }
            ans.Reverse();
            Console.WriteLine(string.Join("", ans));
        }
    }
}
0