結果
| 問題 | No.1450 nahco314's First Problem | 
| コンテスト | |
| ユーザー |  bluemegane | 
| 提出日時 | 2021-05-20 12:58:42 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 23 ms / 2,000 ms | 
| コード長 | 1,064 bytes | 
| コンパイル時間 | 863 ms | 
| コンパイル使用メモリ | 104,448 KB | 
| 実行使用メモリ | 17,792 KB | 
| 最終ジャッジ日時 | 2024-11-08 14:29:25 | 
| 合計ジャッジ時間 | 3,291 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 37 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using static System.Math;
using System;
public class Hello
{
    static void Main()
    {
        var x = long.Parse(Console.ReadLine().Trim());
        if (x == 0) Console.WriteLine(1);
        else getAns(x);
    }
    static void getAns(long x)
    {
        var imin = Max(0, x - 60);
        var imax = x + 60;
        for (long i = imin; i <= imax; i++)
        {
            var bc = bitCount((ulong)i);
            var chk = i ^ bc;
            if (chk == x) { Console.WriteLine(i); return; }
        }
        Console.WriteLine(-1);
    }
    static int bitCount(ulong bits)
    {
        bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555);
        bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333);
        bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f);
        bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff);
        bits = (bits & 0x0000ffff0000ffff) + (bits >> 16 & 0x0000ffff0000ffff);
        return (int)(bits & 0x00000000ffffffff) + (int)(bits >> 32);
    }
}
            
            
            
        