結果

問題 No.589 Counting Even
ユーザー NoNo
提出日時 2018-01-27 00:49:33
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,376 bytes
コンパイル時間 2,566 ms
コンパイル使用メモリ 104,616 KB
実行使用メモリ 23,744 KB
最終ジャッジ日時 2023-08-27 20:34:42
合計ジャッジ時間 5,737 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
21,652 KB
testcase_01 AC 59 ms
21,816 KB
testcase_02 AC 57 ms
23,532 KB
testcase_03 AC 58 ms
23,588 KB
testcase_04 AC 58 ms
21,716 KB
testcase_05 AC 58 ms
21,560 KB
testcase_06 AC 59 ms
21,696 KB
testcase_07 AC 58 ms
23,684 KB
testcase_08 AC 58 ms
21,620 KB
testcase_09 AC 59 ms
21,544 KB
testcase_10 AC 59 ms
21,760 KB
testcase_11 AC 58 ms
23,540 KB
testcase_12 AC 58 ms
19,644 KB
testcase_13 AC 58 ms
23,744 KB
testcase_14 AC 58 ms
21,560 KB
testcase_15 AC 57 ms
21,712 KB
testcase_16 AC 59 ms
21,724 KB
testcase_17 AC 59 ms
23,680 KB
testcase_18 AC 58 ms
21,648 KB
testcase_19 AC 58 ms
21,552 KB
testcase_20 AC 58 ms
23,596 KB
testcase_21 AC 56 ms
19,664 KB
testcase_22 AC 55 ms
21,508 KB
testcase_23 AC 57 ms
21,604 KB
testcase_24 AC 58 ms
21,692 KB
testcase_25 AC 58 ms
23,652 KB
testcase_26 AC 57 ms
21,552 KB
testcase_27 AC 58 ms
21,488 KB
testcase_28 AC 58 ms
21,712 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

namespace y
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());

            long c = 0;
            long[] a = { 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, 2147483647, 4294967295, 8589934591, 17179869183, 34359738367, 68719476735, 137438953471, 274877906943, 549755813887, 1099511627775, 2199023255551, 4398046511103, 8796093022207, 17592186044415, 35184372088831, 70368744177663, 140737488355327, 281474976710655, 562949953421311, 1125899906842623, 2251799813685247, 4503599627370495, 9007199254740991, 18014398509481983, 36028797018963967, 72057594037927935, 144115188075855871, 288230376151711743, 576460752303423487, 1152921504606846975 };
            long h = 1;
            if (n == 1) n = 0;

            while (n != 0)
            {
                var b = a.Where(x => x < n).Max();
                if (b - (n - b - 1) == 0)break;
                c += (b - (n - b - 1)) * h;
                n = (n - (b - (n - b - 1))) / 2;
                if (n == 1) break;
                h *= 2;
            }

            Console.WriteLine(c);
        }
    }
}
0