結果

問題 No.638 Sum of "not power of 2"
ユーザー p_nixp_nix
提出日時 2018-01-27 00:09:16
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 60 ms / 1,000 ms
コード長 1,263 bytes
コンパイル時間 2,175 ms
コンパイル使用メモリ 104,668 KB
実行使用メモリ 22,840 KB
最終ジャッジ日時 2023-08-28 18:16:05
合計ジャッジ時間 3,876 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
20,720 KB
testcase_01 AC 57 ms
20,716 KB
testcase_02 AC 57 ms
18,828 KB
testcase_03 AC 57 ms
18,636 KB
testcase_04 AC 59 ms
22,808 KB
testcase_05 AC 56 ms
20,732 KB
testcase_06 AC 59 ms
20,764 KB
testcase_07 AC 59 ms
22,840 KB
testcase_08 AC 59 ms
20,816 KB
testcase_09 AC 58 ms
20,696 KB
testcase_10 AC 58 ms
20,780 KB
testcase_11 AC 59 ms
22,792 KB
testcase_12 AC 56 ms
18,672 KB
testcase_13 AC 60 ms
20,760 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

namespace prob638
{
    class Program
    {
        public static ulong[] data = new ulong[60];
        static void Main(string[] args)
        {
            data[0] = 1;
            for (int i = 1; i < 60; i++)
            {
                data[i] = data[i-1] * 2;
            }
            long a = long.Parse(Console.ReadLine());
            long ret = -1;
            bool flg = false;
            for (long i = 1; i < a/2+1; i++)
            {
                if (!ispower2((ulong)i) && !ispower2((ulong)(a - i)))
                {
                    flg = true;
                    ret = i;
                    break;
                }
                else
                {
                    flg = false;
                }
            }
            if (flg==false)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine("{0} {1}", ret,(long)(a-ret));
            }
        }

        static bool ispower2(ulong v)
        {
            
            if (Array.IndexOf(data, v)>-1)
            {
                
                return true;
            }
            else
            {
                return false;
            }
            
        }
    }
}
0